Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-maps-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: abort navigation after async rendering if obsolete
21 changes: 12 additions & 9 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ async function initialize(result, target, hydrate) {
const style = document.querySelector('style[data-sveltekit]');
if (style) style.remove();

Object.assign(page, /** @type {import('@sveltejs/kit').Page} */ (result.props.page));
update(/** @type {import('@sveltejs/kit').Page} */ (result.props.page));

root = new app.root({
target,
Expand Down Expand Up @@ -1917,6 +1917,17 @@ async function navigate({
await svelte.tick();
await svelte.tick();

if (token !== nav_token) {
Comment thread
dummdidumm marked this conversation as resolved.
// a new navigation happened while we were waiting for the DOM to update, so abort
nav.reject(new Error('navigation aborted'));
return false;
}

// Check for async rendering error
if (navigation_result.props.page && rendering_error) {
Object.assign(navigation_result.props.page, rendering_error);
}

// we reset scroll before dealing with focus, to avoid a flash of unscrolled content
/** @type {Element | null | ''} */
let deep_linked = null;
Expand Down Expand Up @@ -1951,14 +1962,6 @@ async function navigate({

autoscroll = true;

if (navigation_result.props.page) {
// Check for async rendering error
if (rendering_error) {
Object.assign(navigation_result.props.page, rendering_error);
}
Object.assign(page, navigation_result.props.page);
}

is_navigating = false;

if (type === 'popstate') {
Expand Down
Loading