next.js
7a6376f0 - Give route-shaped dev server strings distinct types

Commit
11 days ago
Give route-shaped dev server strings distinct types Turbopack's entrypoints keep routes in maps keyed by string namespaces that look alike but rarely equal each other: the routes map is keyed by route pathname ("/blog"), and the app entrypoints map by entry name ("/blog/page"). Mixing them up compiles fine and silently never matches — which is how the dev server came to announce every app route as added on every update (fixed at the bottom of this stack). Brand the two namespaces (TurbopackRouteKey, AppEntryName) the way EntryKey already guards entry keys: a plain string can't be used where a branded key is expected, and the brands can't be used in each other's place. Reverting the announcement fix no longer compiles: error TS2345: Argument of type 'TurbopackRouteKey' is not assignable to parameter of type 'AppEntryName'. error TS2345: Argument of type 'string' is not assignable to parameter of type 'TurbopackRouteKey'. Strings enter the namespaces at the NAPI boundary (route construction in swc/index.ts) and leave through message payloads, where the brands widen back to plain strings. normalizedPageToTurbopackStructureRoute returns an entry name — per its own comment it maps a normalized page path back to Turbopack's entry key — and is typed accordingly. No runtime change.
Author
Committer
Parents
Loading