Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/calm-fireants-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only preload links that have a different URL than the current page
5 changes: 4 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,10 @@ function setup_preload() {

const options = get_router_options(a);

if (!options.reload) {
// we don't want to preload data for a page we're already on
const same_url = url && current.url.pathname + current.url.search === url.pathname + url.search;

if (!options.reload && !same_url) {
if (priority <= options.preload_data) {
const intent = get_navigation_intent(url, false);
if (intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
<a href="#hash-target">hash link</a>
<a href="/routing/hashes/b">b</a>
<a href="#replace-state" data-sveltekit-replacestate>replace state</a>

<a data-sveltekit-preload-data href="/routing/hashes/a">/routing/hashes/a</a>
<a data-sveltekit-preload-data href="#preload">#preload</a>
13 changes: 13 additions & 0 deletions packages/kit/test/apps/basics/test/cross-platform/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,19 @@
await expect(page.locator('h1')).not.toHaveText('Oopsie');
});

test('same route hash links work more than once', async ({ page, clicknav, baseURL }) => {
await page.goto('/routing/hashes/a');

await clicknav('[href="#preload"]');
await expect(page.url()).toBe(`${baseURL}/routing/hashes/a#preload`);

await clicknav('[href="/routing/hashes/a"]');
await expect(page.url()).toBe(`${baseURL}/routing/hashes/a`);

await clicknav('[href="#preload"]');
await expect(page.url()).toBe(`${baseURL}/routing/hashes/a#preload`);
});

test('does not rerun load on calls to duplicate preload hash route', async ({ app, page }) => {
await page.goto('/routing/a');

Expand Down Expand Up @@ -769,7 +782,7 @@
expect(await page.textContent('h3')).toBe('bar');
});

test('responds to <form target="_blank"> submission with new tab', async ({ page }) => {

Check warning on line 785 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, ubuntu-latest, firefox, build)

flaky test: responds to <form target="_blank"> submission with new tab

retries: 2
await page.goto('/routing/form-target-blank');

let tabs = page.context().pages();
Expand Down
Loading