From d9ad8c60e725d33b816585908242f5d20995c98c Mon Sep 17 00:00:00 2001 From: Mihael Date: Thu, 3 Mar 2022 11:27:37 +0100 Subject: [PATCH 1/3] . --- .changeset/sour-needles-compete.md | 5 +++++ packages/kit/src/runtime/client/client.js | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .changeset/sour-needles-compete.md diff --git a/.changeset/sour-needles-compete.md b/.changeset/sour-needles-compete.md new file mode 100644 index 000000000000..9c6e36f32417 --- /dev/null +++ b/.changeset/sour-needles-compete.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Change URL just before running root.\$set 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); - } } /** From a5445a11e00af01c9f4bb8ceda3655bb6ffe1479 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 3 Mar 2022 16:19:13 -0500 Subject: [PATCH 2/3] add test --- .../kit/test/apps/basics/src/routes/iframes/index.svelte | 1 + .../apps/basics/src/routes/iframes/nested/child.svelte | 1 + .../apps/basics/src/routes/iframes/nested/parent.svelte | 1 + packages/kit/test/apps/basics/test/test.js | 9 +++++++++ 4 files changed, 12 insertions(+) create mode 100644 packages/kit/test/apps/basics/src/routes/iframes/index.svelte create mode 100644 packages/kit/test/apps/basics/src/routes/iframes/nested/child.svelte create mode 100644 packages/kit/test/apps/basics/src/routes/iframes/nested/parent.svelte 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 @@ +