fix(link): keep auto prefetch from fetching dynamic app routes#1177
Draft
NathanDrake2406 wants to merge 2 commits into
Draft
fix(link): keep auto prefetch from fetching dynamic app routes#1177NathanDrake2406 wants to merge 2 commits into
NathanDrake2406 wants to merge 2 commits into
Conversation
App Router Link treated null, undefined, and auto prefetch as the same full RSC prefetch used by prefetch={true}. That violates Next.js's public prefetch contract and over-fetches dynamic route payloads as soon as links enter the viewport.
The broken assumption was that prefetch only needed a boolean enabled state. Split Link prefetch into disabled, auto, and full modes, emit a small browser route manifest, and allow automatic full RSC prefetch only for matched static app routes while preserving explicit full prefetch.
Add focused tests for the mode mapping and generated route manifest.
commit: |
The interception-context E2E asserts that full RSC prefetch cache keys stay separate by source context. After auto prefetch stops full-fetching dynamic routes, that fixture needs to request the full prefetch mode explicitly.
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.
Overview
<Link prefetch={null}>, omittedprefetch, andprefetch=\"auto\"from behaving likeprefetch={true}for dynamic routes.disabled,auto, andfull, then gate automatic full RSC prefetches through a generated static route manifest.prefetch={true}still opts into full RSC prefetch.null/undefined/\"auto\"no longer trigger full dynamic route payload fetches.packages/vinext/src/shims/link.tsx,packages/vinext/src/entries/app-browser-entry.ts,packages/vinext/src/index.tsWhy
The Link prefetch prop is not a boolean in the App Router contract. Next.js treats
null,undefined, and\"auto\"as automatic prefetch, whiletrueis the explicit full-prefetch mode. Vinext collapsed those states into “enabled”, which meant default links to dynamic routes could fetch full RSC payloads as soon as they entered the viewport.prefetch !== false.prefetch={true}is still allowed to fetch the full route and data.What changed
<Link href=\"/about\" />for a static app route<Link href=\"/blog/hello-world\" />for a dynamic app route<Link href=\"/blog/hello-world\" prefetch={true} />Maintainer review path
packages/vinext/src/shims/link.tsx: mode resolution, static route matching, and the auto-prefetch gate.packages/vinext/src/entries/app-browser-entry.ts: browser route manifest generation.packages/vinext/src/index.ts: passes scanned App Router routes into the browser entry generator.tests/link.test.tsandtests/entry-templates.test.ts: focused behavior and codegen coverage.Validation
vp test run tests/link.test.ts tests/entry-templates.test.tsvp check tests/link.test.ts tests/entry-templates.test.ts packages/vinext/src/shims/link.tsx packages/vinext/src/entries/app-browser-entry.ts packages/vinext/src/client/vinext-next-data.ts packages/vinext/src/index.tsgit diff --checkRisk / compatibility
prefetch=\"auto\" | null, matching App Router Link.prefetch={true}for full prefetch.autocan safely do that work.Non-goals
router.prefetch(), which is already an explicit imperative prefetch API.References
\"auto\",null, andundefinedas automatic App Router prefetch, distinct fromtrue.trueto full prefetch andnull/\"auto\"to automatic/PPR behavior.prefetch=\"auto\"test\"auto\"is an alias for the default automatic behavior.