Skip to content

Commit 49d2ec6

Browse files
authored
fix: ignore external links when automatically preloading (#8961)
1 parent ee8066f commit 49d2ec6

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Diff for: .changeset/six-poems-exist.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: ignore external links when automatically preloading

Diff for: packages/kit/src/runtime/client/client.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,8 @@ export function create_client({ target }) {
221221
});
222222
}
223223

224-
/** @param {URL} url */
225-
async function preload_data(url) {
226-
const intent = get_navigation_intent(url, false);
227-
228-
if (!intent) {
229-
throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
230-
}
231-
224+
/** @param {import('./types').NavigationIntent} intent */
225+
async function preload_data(intent) {
232226
load_cache = {
233227
id: intent.id,
234228
promise: load_route(intent).then((result) => {
@@ -1261,7 +1255,8 @@ export function create_client({ target }) {
12611255

12621256
if (!options.reload) {
12631257
if (priority <= options.preload_data) {
1264-
preload_data(/** @type {URL} */ (url));
1258+
const intent = get_navigation_intent(/** @type {URL} */ (url), false);
1259+
if (intent) preload_data(intent);
12651260
} else if (priority <= options.preload_code) {
12661261
preload_code(get_url_path(/** @type {URL} */ (url)));
12671262
}
@@ -1347,7 +1342,13 @@ export function create_client({ target }) {
13471342

13481343
preload_data: async (href) => {
13491344
const url = new URL(href, get_base_uri(document));
1350-
await preload_data(url);
1345+
const intent = get_navigation_intent(url, false);
1346+
1347+
if (!intent) {
1348+
throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
1349+
}
1350+
1351+
await preload_data(intent);
13511352
},
13521353

13531354
preload_code,

0 commit comments

Comments
 (0)