Skip to content

Commit

Permalink
fix: popstate navigations take pushState navigations into account (
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickG authored Jan 31, 2024
1 parent a6333a5 commit 311fe8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-games-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: `popstate` navigations take `pushState` navigations into account
1 change: 1 addition & 0 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ export function pushState(url, state) {
};

history.pushState(opts, '', resolve_url(url));
has_navigated = true;

page = { ...page, state };
root.$set({ page });
Expand Down
11 changes: 11 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,17 @@ test.describe('Shallow routing', () => {
await expect(page.locator('span')).not.toHaveText(now);
});

test('Does not navigate when going back to shallow route', async ({ baseURL, page }) => {
await page.goto('/shallow-routing/push-state');
await page.locator('[data-id="two"]').click();
await page.goBack();
await page.goForward();

expect(page.url()).toBe(`${baseURL}/shallow-routing/push-state/a`);
await expect(page.locator('h1')).toHaveText('parent');
await expect(page.locator('p')).toHaveText('active: true');
});

test('Replaces state on the current URL', async ({ baseURL, page, clicknav }) => {
await page.goto('/shallow-routing/replace-state/b');
await clicknav('[href="/shallow-routing/replace-state"]');
Expand Down

0 comments on commit 311fe8f

Please sign in to comment.