-
-
Notifications
You must be signed in to change notification settings - Fork 2k
chore: improve error message for prefetching invalid url #7314
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
chore: improve error message for prefetching invalid url #7314
Conversation
🦋 Changeset detectedLatest commit: c3d9c27 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -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.` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Happened to come across
Uncaught (in promise) Error: Attempted to prefetch a URL that does not belong to this app
in an app today and didn't immediately find the cause.The url in the message can help finding where in the application it happened, also added some guidance and docs link for good measure.
In my case it was a link to a page that hadn't been created yet. If thats the only way to reach this error, maybe the url is enough to not confuse users into disabling prefetching too eagerly?
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0