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

Improve error message when prefetching fails
4 changes: 3 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ export function create_client({ target, base, trailing_slash }) {
const intent = get_navigation_intent(url, false);

if (!intent) {
throw new Error('Attempted to prefetch a URL that does not belong to this app');
throw new Error(
`Attempted to prefetch "${url}", a URL that does not belong to this app. To disable prefetching add data-sveltekit-prefetch="off" to a parent. See https://kit.svelte.dev/docs/link-options#data-sveltekit-prefetch for more information.`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the error shouldn't happen if prefetching happened as a result of the user stopping over a link, but only if the app calls prefetch(bad_url). If that's not currently the case then I'd argue it's a bug, and we should fix that instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case it was a newly added href="/some/new/route" . The error happened during dev after the href was added but before +page.svelte was created. So bad url. Maybe skip and warn instead during dev and error only in build? But adding the url to the message seems helpful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but what i'm saying is that data-sveltekit-prefetch shouldn't cause that error, it should be reserved for when you do prefetch('/some/new/route')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So .. we have a bug hiding somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. But adding the url value to the error message helps that case as well. The stacktrace isn't helping because it's internal to kit, so you have to start debugging to get a clue.

I have removed the extra information to avoid confusion.

);
}

load_cache = { id: intent.id, promise: load_route(intent) };
Expand Down