mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #909] [MERGED] Return leaf selected layout segment for named parallel routes #939
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#939
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/909
Author: @NathanDrake2406
Created: 4/26/2026
Status: ✅ Merged
Merged: 4/26/2026
Merged by: @james-elicx
Base:
main← Head:nathan/fix-selected-layout-segment-parallel-routes📝 Commits (1)
dd6f56fReturn leaf selected layout segment for named slots📊 Changes
3 files changed (+63 additions, -18 deletions)
View changed files
📝
packages/vinext/src/shims/navigation.ts(+5 -1)📝
tests/app-router.test.ts(+51 -17)➕
tests/fixtures/app-basic/app/dashboard/@team/members/profile/page.tsx(+7 -0)📄 Description
What this changes
useSelectedLayoutSegment(parallelRoutesKey)now matches Next.js for named parallel routes: the defaultchildrenroute still returns the first child segment, while named slots return the active leaf segment from that slot path.This fixes nested parallel slot routes such as
@team/members/profile, whereuseSelectedLayoutSegments("team")returns["members", "profile"]anduseSelectedLayoutSegment("team")should return"profile".Why
Vinext previously reduced every segment array with
segments[0]. That is only correct for the defaultchildrenroute. Next.js intentionally treats named parallel route keys differently incomputeSelectedLayoutSegment():children: first segmentchildrenparallel route keys: last segmentSource references:
github.com/vercel/next.js@6d4a405f4a/packages/next/src/shared/lib/segment.ts (L32-L49)github.com/vercel/next.js@6d4a405f4a/packages/next/src/client/components/navigation.ts (L310-L338)github.com/vercel/next.js@6d4a405f4a/test/e2e/app-dir/parallel-routes-use-selected-layout-segment/parallel-routes-use-selected-layout-segment.test.ts (L84-L93)github.com/vercel/next.js@6d4a405f4a/test/e2e/app-dir/parallel-routes-use-selected-layout-segment/parallel-routes-use-selected-layout-segment.test.ts (L146-L155)Approach
The shim now returns
nullfor an empty segment list, returns the first segment forundefinedor"children", and returns the final segment for named parallel route keys.The regression test adds a nested
@teamslot fixture and asserts both behaviours together:useSelectedLayoutSegments("team")exposes the full slot path["members", "profile"]useSelectedLayoutSegment("team")returns the leaf segment"profile"Validation
vp test run tests/app-router.test.ts -t "useSelectedLayoutSegment"vp check tests/app-router.test.ts packages/vinext/src/shims/navigation.ts tests/fixtures/app-basic/app/dashboard/@team/members/profile/page.tsxRisks / follow-ups
This is scoped to the client navigation shim reduction rule. It does not change route discovery or segment-map construction, which already preserves the full slot segment path needed for this behaviour.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.