-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[fix] tighten up navigation and invalidation logic #6924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f64a51b
[fix] tighten up navigation and invalidation logic
dummdidumm 9a2437b
fix redirect token logic
dummdidumm e0def0a
batch synchronous invalidations
dummdidumm 32d031d
tests
dummdidumm a98b6e7
tweak load cache timing and reduce code a little
dummdidumm 42a7944
Apply suggestions from code review
dummdidumm 6262e6a
lint
dummdidumm 2dbe1e6
merge
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
[fix] tighten up navigation and invalidation logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/+layout.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
import { get } from 'svelte/store'; | ||
import { get_layout, redirect_state } from './state'; | ||
|
||
/** @type {import('./$types').LayoutLoad} */ | ||
export function load({ depends }) { | ||
depends('invalid:layout'); | ||
|
||
if (get(redirect_state) === 'running') { | ||
redirect_state.set('done'); | ||
throw redirect(307, '/load/invalidation/multiple/redirect'); | ||
} | ||
|
||
return new Promise((resolve) => | ||
setTimeout( | ||
() => | ||
resolve({ | ||
count_layout: get_layout(), | ||
redirect_mode: get(redirect_state) | ||
}), | ||
Math.random() * 500 | ||
) | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/+layout.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script> | ||
import { invalidate, invalidateAll } from '$app/navigation'; | ||
import { page } from '$app/stores'; | ||
import { increment_layout, increment_page } from './state'; | ||
|
||
/** @param {string} str */ | ||
async function update(str) { | ||
if (str !== 'page') { | ||
increment_layout(); | ||
} | ||
if (str !== 'layout') { | ||
increment_page(); | ||
} | ||
|
||
if (str === 'all') { | ||
invalidateAll(); | ||
} else { | ||
invalidate(`invalid:${str}`); | ||
} | ||
} | ||
</script> | ||
|
||
<button class="layout" on:click={() => update('layout')}>Invalidate layout</button> | ||
<button class="page" on:click={() => update('page')}>Invalidate page</button> | ||
<button class="all" on:click={() => update('all')}>Invalidate all</button> | ||
|
||
<p>layout: {$page.data.count_layout}, page: {$page.data.count_page}</p> | ||
|
||
<slot /> |
15 changes: 15 additions & 0 deletions
15
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/+page.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { get_page } from './state'; | ||
|
||
/** @type {import('./$types').PageLoad} */ | ||
export function load({ depends }) { | ||
depends('invalid:page'); | ||
return new Promise((resolve) => | ||
setTimeout( | ||
() => | ||
resolve({ | ||
count_page: get_page() | ||
}), | ||
Math.random() * 500 | ||
) | ||
); | ||
} |
Empty file.
14 changes: 14 additions & 0 deletions
14
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/redirect/+page.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
import { redirect_state } from '../state'; | ||
|
||
/** @type {import('./$types').PageLoad} */ | ||
export async function load({ parent }) { | ||
const { redirect_mode } = await parent(); | ||
if (redirect_mode === 'start') { | ||
redirect_state.set('running'); | ||
throw redirect(307, '/load/invalidation/multiple'); | ||
} | ||
if (redirect_mode === 'running') { | ||
throw new Error('Shouldnt get redirected here with state "running"'); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/redirect/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
import { invalidateAll } from '$app/navigation'; | ||
import { redirect_state } from '../state'; | ||
|
||
function redirect() { | ||
redirect_state.set('start'); | ||
invalidateAll(); | ||
} | ||
</script> | ||
|
||
<button class="redirect" on:click={redirect}>redirect</button> | ||
<p class="redirect-state">Redirect state: {$redirect_state}</p> |
22 changes: 22 additions & 0 deletions
22
packages/kit/test/apps/basics/src/routes/load/invalidation/multiple/state.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
let count_layout = 0; | ||
let count_page = 0; | ||
|
||
export const redirect_state = writable('initial'); | ||
|
||
export function increment_layout() { | ||
count_layout++; | ||
} | ||
|
||
export function increment_page() { | ||
count_page++; | ||
} | ||
|
||
export function get_layout() { | ||
return count_layout; | ||
} | ||
|
||
export function get_page() { | ||
return count_page; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.