Skip to content

Commit d34298e

Browse files
Should fix 4177 navigation to pages with iframe with relative urls are broken (#4191)
* . * add test * Update .changeset/sour-needles-compete.md Co-authored-by: Rich Harris <[email protected]>
1 parent 7f958dd commit d34298e

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

.changeset/sour-needles-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Update history immediately before updating DOM

packages/kit/src/runtime/client/client.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function create_client({ target, session, base, trailing_slash }) {
187187
* @param {import('./types').NavigationIntent} intent
188188
* @param {string[]} redirect_chain
189189
* @param {boolean} no_cache
190-
* @param {{hash?: string, scroll: { x: number, y: number } | null, keepfocus: boolean}} [opts]
190+
* @param {{hash?: string, scroll: { x: number, y: number } | null, keepfocus: boolean, details: { replaceState: boolean, state: any } | null}} [opts]
191191
*/
192192
async function update(intent, redirect_chain, no_cache, opts) {
193193
const current_token = (token = {});
@@ -244,6 +244,13 @@ export function create_client({ target, session, base, trailing_slash }) {
244244

245245
updating = true;
246246

247+
if (opts && opts.details) {
248+
const { details } = opts;
249+
const change = details.replaceState ? 0 : 1;
250+
details.state[INDEX_KEY] = current_history_index += change;
251+
history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', intent.url);
252+
}
253+
247254
if (started) {
248255
current = navigation_result.state;
249256

@@ -871,7 +878,8 @@ export function create_client({ target, session, base, trailing_slash }) {
871878

872879
await update(intent, redirect_chain, false, {
873880
scroll,
874-
keepfocus
881+
keepfocus,
882+
details
875883
});
876884

877885
navigating--;
@@ -885,12 +893,6 @@ export function create_client({ target, session, base, trailing_slash }) {
885893

886894
stores.navigating.set(null);
887895
}
888-
889-
if (details) {
890-
const change = details.replaceState ? 0 : 1;
891-
details.state[INDEX_KEY] = current_history_index += change;
892-
history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', intent.url);
893-
}
894896
}
895897

896898
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="/iframes/nested/parent">parent</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello from the child</h1>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<iframe title="Child content" src="./child" />

packages/kit/test/apps/basics/test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,15 @@ test.describe.parallel('Routing', () => {
21562156
await page.evaluate('window.fulfil_navigation && window.fulfil_navigation()');
21572157
expect(await page.url()).toBe(`${baseURL}/routing/cancellation/b`);
21582158
});
2159+
2160+
test('Relative paths are relative to the current URL', async ({ page, clicknav }) => {
2161+
await page.goto('/iframes');
2162+
await clicknav('[href="/iframes/nested/parent"]');
2163+
2164+
expect(await page.frameLocator('iframe').locator('h1').textContent()).toBe(
2165+
'Hello from the child'
2166+
);
2167+
});
21592168
});
21602169

21612170
test.describe.parallel('Session', () => {

0 commit comments

Comments
 (0)