Files
Nathan Nguyen 7d9f4a09b7 feat: implement parallelRoutesKey support in useSelectedLayoutSegment(s) (#737)
* feat: migrate LayoutSegmentContext to segmentMap for parallelRoutesKey

Context type changes from string[] to SegmentMap — a record with a
required "children" key plus optional parallel route keys. useChildSegments()
now accepts a parallelRoutesKey parameter to index into the map.

Consumers not yet updated — entry template and boundary rendering still
use the old childSegments prop. Next commit updates them.

* refactor: update all LayoutSegmentProvider consumers to segmentMap

Mechanical change: every createElement(LayoutSegmentProvider, { childSegments })
becomes createElement(LayoutSegmentProvider, { segmentMap: { children: ... } }).
Behavioral output is identical — useSelectedLayoutSegments() returns the
same values. The segmentMap structure is ready for parallel slot entries.

* test: add parallelRoutesKey integration tests

Verifies useSelectedLayoutSegments(parallelRoutesKey) returns correct
per-slot segments through the full SSR pipeline. Flat slots correctly
return [] until PR 2 populates per-slot entries in the segmentMap.

* refactor: remove as cast from useSelectedLayoutSegments

SegmentMap arrays changed from readonly string[] to string[] to match
Next.js public API return type without requiring a forbidden as cast.
The map itself stays Readonly — arrays are created fresh at each layout
boundary so mutable typing is safe.

* Update packages/vinext/src/shims/layout-segment-context.tsx

Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>

* Update packages/vinext/src/shims/navigation.ts

Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>

* Update packages/vinext/src/shims/layout-segment-context.tsx

Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>

---------

Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>
Co-authored-by: James Anderson <james@eli.cx>
2026-04-01 21:17:47 +00:00
..
2026-02-24 09:29:39 -06:00