Skip to content

fix: Silently skip prefetching external URLs instead of warning #6518

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

Conversation

Greenheart
Copy link
Contributor

Fix #6463 by automatically skipping prefetching of external URLs instead of warning app developers. This aligns with how Next.js solves the same problem.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 1, 2022

🦋 Changeset detected

Latest commit: 40824bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@Rich-Harris
Copy link
Member

Thank you! I think the error is useful in the case where you're programmatically prefetching. What about changing the behaviour of trigger_prefetch to ignore any links that would normally be ignored? (Might need to abstract some logic out from the click handler to avoid repetition)

@Greenheart
Copy link
Contributor Author

Thanks for the feedback! That sounds like a good way forward. When app devs call prefetch() there's a clear intention and the warning would be helpful.

I'll explore this further in the coming days. This would be a fun contribution to make!

For automatic prefetching with `data-sveltekit-prefetc`, silently return early like before.
@netlify
Copy link

netlify bot commented Sep 2, 2022

Deploy Preview for kit-demo ready!

Name Link
🔨 Latest commit 40824bb
🔍 Latest deploy log https://app.netlify.com/sites/kit-demo/deploys/6311a53beee3450008f2835d
😎 Deploy Preview https://deploy-preview-6518--kit-demo.netlify.app/build
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Greenheart
Copy link
Contributor Author

Greenheart commented Sep 2, 2022

Update:

Prefetching never happens for external URLs.

The difference is that programmatic calls to prefetch() will now throw the same error as before, while trigger_prefetch that is activated by data-sveltekit-prefetch silently fails just like the previous commit.

Remaning TODOs

  • I get two failing tests locally which didn't fail before. Any ideas what might have caused this? Perhaps because we're now inconsistent and throwing errors in one case but not in other cases? Or this might be caused by test flakiness of some kind.
@sveltejs/kit:test:     [chromium-dev] › test/client.test.js:309:2 › Errors › Root error falls back to error.html ======
@sveltejs/kit:test:     [chromium-dev] › test/client.test.js:360:2 › Load › accessing url.hash from load errors and suggests using page store

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

CI succeeded and I don't get these test failures locally, so I'd say we are good - thank you 👍

@dummdidumm dummdidumm merged commit d9a8f4b into sveltejs:master Sep 2, 2022
@github-actions github-actions bot mentioned this pull request Sep 2, 2022
@Greenheart Greenheart deleted the feature/silently-prevent-external-prefetching branch September 2, 2022 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

silence errors coming from data-sveltekit-prefetch
3 participants