Skip to content

fix(app-router): apply slot override params to parallel slot segment map#790

Merged
james-elicx merged 2 commits intocloudflare:mainfrom
NathanDrake2406:fix/bug2-slot-override-segments
Apr 8, 2026
Merged

fix(app-router): apply slot override params to parallel slot segment map#790
james-elicx merged 2 commits intocloudflare:mainfrom
NathanDrake2406:fix/bug2-slot-override-segments

Conversation

@NathanDrake2406
Copy link
Copy Markdown
Contributor

@NathanDrake2406 NathanDrake2406 commented Apr 8, 2026

Summary

  • make slot segment-map resolution use the same effective params as slot rendering (slotOverride.params when present, otherwise matched route params)
  • keep behavior unchanged when no override exists
  • add regression coverage in app-page-route-wiring for both override and non-override paths

Testing

  • vp check tests/app-page-route-wiring.test.ts packages/vinext/src/server/app-page-route-wiring.tsx
  • vp test run tests/app-page-route-wiring.test.ts

Notes

  • vp test run tests/app-router.test.ts -t "useSelectedLayoutSegments" is currently blocked in this worktree by an existing environment dependency error: Cannot find package 'magic-string' from packages/vinext/src/plugins/instrumentation-client.ts.

Copilot AI review requested due to automatic review settings April 8, 2026 07:36
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@790

commit: 14dc4b5

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a mismatch in the App Router’s parallel slot segment-map resolution by ensuring slot segment maps are resolved using the same “effective params” as slot rendering (slot override params when present; otherwise matched route params). It also adds regression tests to cover both override and non-override behaviors.

Changes:

  • Use slot override params (when provided) to resolve parallel slot segmentMap entries.
  • Preserve existing behavior by falling back to matchedParams when no slot override exists.
  • Add unit regression coverage to validate slot segment resolution with and without overrides.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/vinext/src/server/app-page-route-wiring.tsx Updates slot segment-map resolution to use override-effective params, aligning segment map behavior with slot rendering.
tests/app-page-route-wiring.test.ts Adds tests asserting correct useSelectedLayoutSegments("sidebar") output for both override and non-override cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 333 to 337
continue;
}
const slotOverride = options.slotOverrides?.[slotName];
const slotParams = slotOverride?.params ?? options.matchedParams;
if (slot.routeSegments) {
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slot override/params resolution logic is now duplicated (once when building slotElement props and again when building the segmentMap). Consider extracting a small helper (e.g. getEffectiveSlotParams(slotName)) or precomputing effective params per slot for the current layout index, so these two paths can’t drift over time.

Copilot uses AI. Check for mistakes.
@james-elicx
Copy link
Copy Markdown
Collaborator

/bigbonk review

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 8, 2026

UnknownError: The operation timed out.

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 8, 2026

@james-elicx Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@james-elicx
Copy link
Copy Markdown
Collaborator

/bigbonk review

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. The bug was that resolveAppPageChildSegments for parallel slots always used options.matchedParams (the parent route's params) instead of the slot override's params. This meant useSelectedLayoutSegments("slotName") would return unresolved dynamic segments (e.g. [id] instead of 42) when a slot override provided different params.

The fix correctly extracts a getEffectiveSlotParams helper — addressing the Copilot review comment about deduplication — and uses it in both the slot element rendering loop and the segment map construction loop. Tests cover both the override and fallback paths.

All 12 tests pass locally.

@@ -181,6 +183,90 @@ describe("app page route wiring helpers", () => {
expect(html).toContain('data-segments="blog|post"');
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: now that RootLayout renders data-sidebar-segments, the existing test here could assert that attribute too (it would be empty since the sidebar slot has no routeSegments). Not blocking — just a completeness note.

Suggested change
});
expect(html).toContain('data-segments="blog|post"');
expect(html).toContain('data-sidebar-segments=""');
});

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 8, 2026

Review submitted. Here's a summary of my assessment:

Approved. The fix is correct and well-scoped:

  • Bug: resolveAppPageChildSegments for parallel slots in the segment map always used options.matchedParams instead of the slot override's params. This caused useSelectedLayoutSegments("slotName") to return unresolved dynamic segments (e.g. [id] literal instead of 42) when a slot override provided different params.

  • Fix: Extracts a getEffectiveSlotParams(slotName) helper (addressing the Copilot dedup concern) and uses it consistently in both the slot element rendering and segment map construction loops.

  • Tests: Two new focused tests cover the override path (params: { id: "42" } resolves to members|42) and the fallback path (matchedParams: { id: "24" } resolves to members|24). All 12 tests pass.

  • One minor suggestion: The existing "wires templates, slots..." test could also assert data-sidebar-segments="" now that RootLayout renders that attribute (the sidebar in that test has no routeSegments). Not blocking.

github run

@james-elicx james-elicx merged commit 794fd95 into cloudflare:main Apr 8, 2026
25 checks passed
@NathanDrake2406 NathanDrake2406 deleted the fix/bug2-slot-override-segments branch April 8, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants