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

ignore external links when automatically preloading #8961

Merged
merged 1 commit into from
Feb 9, 2023
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/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