Skip to content

Commit

Permalink
fix: ignore external links when automatically preloading (#8961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 9, 2023
1 parent ee8066f commit 49d2ec6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-poems-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: ignore external links when automatically preloading
21 changes: 11 additions & 10 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,8 @@ export function create_client({ target }) {
});
}

/** @param {URL} url */
async function preload_data(url) {
const intent = get_navigation_intent(url, false);

if (!intent) {
throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
}

/** @param {import('./types').NavigationIntent} intent */
async function preload_data(intent) {
load_cache = {
id: intent.id,
promise: load_route(intent).then((result) => {
Expand Down Expand Up @@ -1261,7 +1255,8 @@ export function create_client({ target }) {

if (!options.reload) {
if (priority <= options.preload_data) {
preload_data(/** @type {URL} */ (url));
const intent = get_navigation_intent(/** @type {URL} */ (url), false);
if (intent) preload_data(intent);
} else if (priority <= options.preload_code) {
preload_code(get_url_path(/** @type {URL} */ (url)));
}
Expand Down Expand Up @@ -1347,7 +1342,13 @@ export function create_client({ target }) {

preload_data: async (href) => {
const url = new URL(href, get_base_uri(document));
await preload_data(url);
const intent = get_navigation_intent(url, false);

if (!intent) {
throw new Error(`Attempted to preload a URL that does not belong to this app: ${url}`);
}

await preload_data(intent);
},

preload_code,
Expand Down

0 comments on commit 49d2ec6

Please sign in to comment.