Skip to content

Commit

Permalink
[fix] Silently skip prefetching external URLs instead of warning (#6518)
Browse files Browse the repository at this point in the history
Fix #6463 by automatically skipping prefetching of external URLs instead of warning app developers.
  • Loading branch information
Greenheart committed Sep 2, 2022
1 parent 368dc99 commit d9a8f4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nice-poets-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Silently skip prefetching of external URLs when using `data-sveltekit-prefetch`. Warn like before when calling `prefetch()` for external URLs.
8 changes: 7 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ export function create_client({ target, base, trailing_slash }) {

/** @param {URL} url */
function get_navigation_intent(url) {
if (url.origin !== location.origin || !url.pathname.startsWith(base)) return;
if (is_external_url(url)) return;

const path = decodeURI(url.pathname.slice(base.length) || '/');

Expand All @@ -962,6 +962,11 @@ export function create_client({ target, base, trailing_slash }) {
}
}

/** @param {URL} url */
function is_external_url(url) {
return url.origin !== location.origin || !url.pathname.startsWith(base);
}

/**
* @param {{
* url: URL;
Expand Down Expand Up @@ -1156,6 +1161,7 @@ export function create_client({ target, base, trailing_slash }) {
const trigger_prefetch = (event) => {
const { url, options } = find_anchor(event);
if (url && options.prefetch === '') {
if (is_external_url(url)) return;
prefetch(url);
}
};
Expand Down

0 comments on commit d9a8f4b

Please sign in to comment.