next.js
59ad3de6 - Preserve closed-parameter restrictions in client route prediction (#98889)

Commit
21 hours ago
Preserve closed-parameter restrictions in client route prediction (#98889) ## Summary Preserve the restrictions of `dynamicParams = false` in client route prediction, independently of the proposed parameter-matching API. For `/products/[slug]` with only `allowed` generated during the build, learning `/products/allowed` must not imply that `/products/rejected` exists. This remains true when the page never reads `slug`. The transport-tree builder now attaches `PrefetchHint.IsClosedParam` to the affected dynamic node, rather than putting a route-level bit on the response root or copying it to every prefetch node. Live rendering, error trees, and prefetch-hint collection preserve that placement. Legacy `dynamicParams = false` closes the entire parameter tuple. For `/catalog/[lang]/products/[slug]/details`, both `[lang]` and `[slug]` receive the hint; the static segments do not. Shared ancestors refresh their hints even when their UI is reused: navigating between open and closed pages under the same `[slug]` must add or clear the restriction. Client behavior remains conservative: optimistic route prediction declines a tree containing any closed parameter and asks the server to resolve the destination. Existing apps combining `dynamicParams = false` with `experimental.optimisticRouting` therefore lose prediction for those routes. Sending allowed parameter values to the client and predicting valid destinations from that list is future work, not part of this change. This PR is an independent prerequisite extracted from #97393. It does not enable Cache Components, introduce parameter-matching configuration, or change which parameter values are allowed. The later API layer supplies exact closed-parameter names for routes with a closed prefix and an open suffix. ## Verification - The legacy routing/navigation fixture runs with Cache Components disabled. Revised node-placement assertions fail against the old response-root representation. The shared-sibling navigation test also reproduced stale hints before the skipped-ancestor refresh was added. - Initial documents and live client navigations with `prefetch={false}` place the hint on `[slug]`; open routes carry no closure hint. A nested legacy route marks both dynamic parameters, and open/closed sibling navigation updates a reused ancestor. - Five tests pass in development with both Turbopack and Webpack. The three existing prefetch-dependent scenarios retain their production-only gates; all eight tests pass in production with both bundlers. - The seven production scenarios present before adding shared-sibling navigation also passed with optimistic routing disabled in the Webpack axis-A configuration. - Existing config and transport-tree helper unit suites pass (22 tests and one snapshot), and repository TypeScript checks pass. - The eight-test legacy fixture also passes on the integrated API head. An exploratory dev run of the combined routing-404 scenario encountered an intermittent Turbopack `NoFallbackError`/500; a subsequent run returned the expected 404. This PR does not fix that observation or claim dev coverage for that production-only scenario. <!-- NEXT_JS_LLM -->
Author
Parents
Loading