Repository navigation
feat(pages): add an app-wide default prefetch strategy for Link - #694
Merged
cpojer merged 2 commits intoNov 4, 2026
Merged
Conversation
Adapter plugins accept `prefetch.defaultStrategy`, which takes the same
values as Link's `prefetch` prop and defaults to `false`. A Link without
its own `prefetch` uses it; a Link's own value replaces it, and
`prefetch={false}` opts out. The default applies only to GET links that
don't use `reloadDocument`, so mutation links keep working. An invalid
strategy fails when the plugin is configured.
Links to other sites are no longer prefetched. The router matches only
the path, so they would have prefetched a same-path page of this app.
The Pages guide gains a short Prefetching section, and the Pages API
reference documents every strategy, `cacheFor`, and the plugin options.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fetch-strategy # Conflicts: # docs/guide/pages-routing/overview.md # packages/svelte/src/runtime/Link.svelte # packages/void/src/pages/link.ts # packages/vue/src/runtime/link.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Until now, a
Linkprefetched only when it setprefetchitself, so an app that wanted hover prefetching everywhere had to add the prop to everyLink. Adapter plugins now takeprefetch.defaultStrategy, next to the existinghoverDelayandcacheFor:true,false,'hover' | 'click' | 'mount' | 'visible', or an array of them. The default isfalse, so existing apps don't change, andvoid initdoesn't turn it on. I propose changing the default for new apps. See below.prefetchreplaces the default. Values aren't merged, so a Link can drop a strategy the default includes.prefetch={false}opts that one Link out, andtruestill means'hover'.methodorreloadDocumentskip it rather than throwing. An explicitprefetchon a POST Link still throws, as before.prefetch.defaultStrategyand lists the accepted values.Behavior change: no prefetch for other sites
prefetchLinknow skips URLs on another origin. The router matches only the path, so a prefetching Link tohttps://example.com/userswould have loaded this app's/userspage. This already affected explicitprefetch. With an app-wide default it would have affected most external links.Open questions
prefetch: { defaultStrategy: true }in the config can look a bit weird, but it's aligned with theLinkinstanceprefetchvalues. Lemme know if I should removetrueas an accepted value for the config.prefetch.defaultStrategy: 'hover'for new apps? I personally think this is the most balanced default. What other frameworks do:Testing
linkPrefetchStrategies: the default, replacement by the prop, opt-out, and non-GET linksprefetchLink: skipping other origins and non-HTTP schemesresolvePrefetchConfig: defaults and validationLinkunder a router default. Vue, Svelte and Solid have no DOM test setup, so their Links are covered by typecheck, the shared unit tests and the generated-entry test.vp run checkpasses, andvp run testpasses for all 536 affected test files.vp test run, three files timed out under load:tanstack-startdev (the server needed 19 s against a 20 s limit),plugin-cloudflare-v2andworker-build-node-require(5 s each). None touch Link or prefetch code, and all three pass when rerun on their own.