You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two load functions (one in +layout.ts and +page.ts) with following conditions:
using provided fetch in load function
+layout.ts calls hypothetical endpoint GET /api/random-number
+page.ts calls hypothetical endpoint GET /api/todos
+page.ts calls await parent() to fetch LayoutData from +layout.ts.
The expected invalidation behaviour is:
when invalidate('/api/random-numbers'), both load in +layout.ts and +page.ts re-run because await parent() exists in +page.ts
when invalidate('/api/todos'), only load in +page.ts runs because layout doesn't need any refresh - not as expected
invalidate('/api/todos') follows the expected behaviour when there was no previous invalidate('/api/random-numbers') call, but it also re-runs the load in +layout.ts if invalidate('/api/random-numbers') was previously called.
This isn't expected as the invalidation behaviour is different depending on the previous invalidation context. I was expecting that the invalidate call on +layout.ts will stay valid in subsequent page invalidation call once the layout load hydrate backs into the component, but that seems to be not the case.
I've tried to understand what is going on and it seemingly relates to invalidated that tracks all invalidation requests in client context (created by create_client in client.js). It looks like invalidate() only appends the URL/function to the invalidated array, but there is no concept of invalidation being done and removing them from this invalidated tracker.
Open DevTools. The reproduction does the following after it mounts and log the trace to console:
OK: when the +page.svelte first loads, calls load in both +layout.ts and +page.ts
OK: after 2 seconds, in +page.svelte, call invalidate('/api/todos') - this calls load in +page.ts
OK: after 4 seconds, in +page.svelte, call invalidate('/api/random-number') - this calls load in both +layout.ts and +page.ts
Unexpected: after 4 seconds, in +page.svelte, call invalidate('/api/todos') - this unexpectedly calls load in both +layout.ts and +page.ts
Logs
---load in +layout.ts called---
GET /random-number
---load in +page.ts called---
GET /todos
---INITIAL LOAD COMPLETE---
---load in +page.ts called---
GET /todos
---FIRST INVALIDATION COMPLETE: PAGE---
---load in +layout.ts called---
GET /random-number
---load in +page.ts called---
GET /todos
---SECOND INVALIDATION COMPLETE: LAYOUT---
---load in +layout.ts called---
GET /random-number
---load in +page.ts called---
GET /todos
---THIRD INVALIDATION COMPLETE: PAGE---
The text was updated successfully, but these errors were encountered:
soonmyeongyoon
changed the title
invalidate an URL in +layout.ts then invalidate an URL in +page.ts makes the layout load function run twiceinvalidate an URL in +layout.ts then invalidate an URL in +page.ts makes both layout and page load function run
Jun 21, 2023
Describe the bug
There are two
load
functions (one in+layout.ts
and+page.ts
) with following conditions:+layout.ts
calls hypothetical endpoint GET/api/random-number
+page.ts
calls hypothetical endpoint GET/api/todos
+page.ts
callsawait parent()
to fetch LayoutData from+layout.ts
.The expected invalidation behaviour is:
invalidate('/api/random-numbers')
, bothload
in+layout.ts
and+page.ts
re-run becauseawait parent()
exists in+page.ts
invalidate('/api/todos')
, onlyload
in+page.ts
runs because layout doesn't need any refresh - not as expectedinvalidate('/api/todos')
follows the expected behaviour when there was no previousinvalidate('/api/random-numbers')
call, but it also re-runs theload
in+layout.ts
ifinvalidate('/api/random-numbers')
was previously called.This isn't expected as the invalidation behaviour is different depending on the previous invalidation context. I was expecting that the
invalidate
call on+layout.ts
will stay valid in subsequent page invalidation call once the layout load hydrate backs into the component, but that seems to be not the case.I've tried to understand what is going on and it seemingly relates to
invalidated
that tracks all invalidation requests in client context (created bycreate_client
inclient.js
). It looks likeinvalidate()
only appends the URL/function to theinvalidated
array, but there is no concept of invalidation being done and removing them from thisinvalidated
tracker.Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-2p2hwu?file=src%2Froutes%2F%2Bpage.svelte
Open DevTools. The reproduction does the following after it mounts and log the trace to console:
+page.svelte
first loads, callsload
in both+layout.ts
and+page.ts
+page.svelte
, callinvalidate('/api/todos')
- this callsload
in+page.ts
+page.svelte
, callinvalidate('/api/random-number')
- this callsload
in both+layout.ts
and+page.ts
+page.svelte
, callinvalidate('/api/todos')
- this unexpectedly callsload
in both+layout.ts
and+page.ts
Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: