diff --git a/.changeset/sour-needles-compete.md b/.changeset/sour-needles-compete.md new file mode 100644 index 000000000000..7008b4a5c123 --- /dev/null +++ b/.changeset/sour-needles-compete.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Update history immediately before updating DOM diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index af24e0c4d46c..069f1c81c7b6 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -187,7 +187,7 @@ export function create_client({ target, session, base, trailing_slash }) { * @param {import('./types').NavigationIntent} intent * @param {string[]} redirect_chain * @param {boolean} no_cache - * @param {{hash?: string, scroll: { x: number, y: number } | null, keepfocus: boolean}} [opts] + * @param {{hash?: string, scroll: { x: number, y: number } | null, keepfocus: boolean, details: { replaceState: boolean, state: any } | null}} [opts] */ async function update(intent, redirect_chain, no_cache, opts) { const current_token = (token = {}); @@ -244,6 +244,13 @@ export function create_client({ target, session, base, trailing_slash }) { updating = true; + if (opts && opts.details) { + const { details } = opts; + const change = details.replaceState ? 0 : 1; + details.state[INDEX_KEY] = current_history_index += change; + history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', intent.url); + } + if (started) { current = navigation_result.state; @@ -871,7 +878,8 @@ export function create_client({ target, session, base, trailing_slash }) { await update(intent, redirect_chain, false, { scroll, - keepfocus + keepfocus, + details }); navigating--; @@ -885,12 +893,6 @@ export function create_client({ target, session, base, trailing_slash }) { stores.navigating.set(null); } - - if (details) { - const change = details.replaceState ? 0 : 1; - details.state[INDEX_KEY] = current_history_index += change; - history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', intent.url); - } } /** diff --git a/packages/kit/test/apps/basics/src/routes/iframes/index.svelte b/packages/kit/test/apps/basics/src/routes/iframes/index.svelte new file mode 100644 index 000000000000..b1c6dd8649ef --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/iframes/index.svelte @@ -0,0 +1 @@ +parent diff --git a/packages/kit/test/apps/basics/src/routes/iframes/nested/child.svelte b/packages/kit/test/apps/basics/src/routes/iframes/nested/child.svelte new file mode 100644 index 000000000000..95d405856a2a --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/iframes/nested/child.svelte @@ -0,0 +1 @@ +

Hello from the child

diff --git a/packages/kit/test/apps/basics/src/routes/iframes/nested/parent.svelte b/packages/kit/test/apps/basics/src/routes/iframes/nested/parent.svelte new file mode 100644 index 000000000000..90cc91d81d6c --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/iframes/nested/parent.svelte @@ -0,0 +1 @@ +