This project demonstrates unexpected behavior with SvelteKit invalidations.
After a dependency has been marked invalid, further invalidations of any resource will rerun a
load
function if it is dependent on the first resource, even after load
has run following the
first invalidation. Invalidated resources remain invalid until the next navigation.
If invalidateAll
has marked all dependencies invalid, further invalidations of any resource will
rerun any load
function. This condition remains until the next navigation.
An application that:
- depends on several resources, individually, over several pages, and
- receives a stream of resource ids from a server that it invalidates, and
- invalidates the resource for the current page
will needlessly cause the page to refresh as it invalidates each following resource.
The following steps demonstrate the issue. Key events are logged to the console as:
-
beforeNavigate
andafterNavigate
lifecycle events- navigation before
- navigation after
-
load
invocations, andload
calls todepends
- load
- load
depends('*resource*')
-
Event handler calls to
invalidate
orinvalidateAll
- event
invalidate('*resource*')
- event
invalidateAll
- event
Observe that the table background flashes to indicate when the view renders.
Console
- navigation before
- load
- navigation after
Console
- event
invalidate('resource:a')
✔ The view does not render, as expected.
Console
- navigation before
- load
- navigation after
Console
- navigation before
- load
- load
depends('resource:a')
- navigation after
Console
- event
invalidate('resource:a')
- load
- load
depends('resource:a')
✔ The view renders, as expected.
Console
- navigation before
- load
- navigation after
Console
- navigation before
- load
- load
depends('resource:a')
- navigation after
Console
- event
invalidate('resource:b')
✔ The view does not render, as expected.
Console
- event
invalidate('resource:a')
- load
- load
depends('resource:a')
✔ The view renders, as expected.
Console
- event
invalidate('resource:b')
- load
- load
depends('resource:a')
✖ The view renders, unexpectedly.
Console
- navigation before
- load
- navigation after
Console
- event
invalidate('resource:a')
✔ The view does not render, as expected.
Console
- event
invalidateAll()
- load
✔ The view renders, as expected.
Console
- event
invalidate('resource:a')
- load
✖ The view renders, unexpectedly.