Skip to content
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

Should fix 4177 navigation to pages with iframe with relative urls are broken #4191

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/sour-needles-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Change URL just before running root.\$set
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 10 additions & 8 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {});
Expand Down Expand Up @@ -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;

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

await update(intent, redirect_chain, false, {
scroll,
keepfocus
keepfocus,
details
});

navigating--;
Expand All @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="/iframes/nested/parent">parent</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello from the child</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe title="Child content" src="./child" />
9 changes: 9 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,15 @@ test.describe.parallel('Routing', () => {
await page.evaluate('window.fulfil_navigation && window.fulfil_navigation()');
expect(await page.url()).toBe(`${baseURL}/routing/cancellation/b`);
});

test('Relative paths are relative to the current URL', async ({ page, clicknav }) => {
await page.goto('/iframes');
await clicknav('[href="/iframes/nested/parent"]');

expect(await page.frameLocator('iframe').locator('h1').textContent()).toBe(
'Hello from the child'
);
});
});

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