fix: use closest ancestor parallel slot instead of farthest#545
Conversation
commit: |
discoverInheritedParallelSlots iterates from root to leaf, but used a `has()` guard that let the first (farthest) ancestor win. Remove the guard so later (closer) ancestors overwrite earlier ones.
d37b09c to
22d3c03
Compare
|
/bigbonk review |
There was a problem hiding this comment.
Clean, correct fix with a good test. The bug analysis is spot-on: the old if (!slotMap.has(slot.name)) guard caused the first (root-level) slot to win since iteration goes root-to-leaf, when the desired behavior is for the closest ancestor to win. Removing the guard lets later iterations naturally overwrite earlier ones, which is consistent with how the isOwnDir branch already works.
The test creates exactly the right scenario (same @sidebar at root and dashboard levels) and asserts the correct outcome for a leaf route under dashboard.
| expect(sidebarSlot).toBeDefined(); | ||
|
|
||
| // The dashboard-level @sidebar (closest ancestor) should win | ||
| expect(sidebarSlot!.defaultPath).not.toBeNull(); |
There was a problem hiding this comment.
Nit: You could also assert that sidebarSlot!.layoutIndex matches the dashboard layout (index 1) rather than the root layout (index 0). That would make the test even more precise about which slot was selected, since the fix also ensures layoutIndex is correct. Not blocking — the defaultPath assertion is sufficient to prove the right slot won.
|
Approved the PR. Here's a summary of the review: Verdict: Approved The fix is correct and minimal. The old The test is well-constructed: it sets up the exact scenario (same |
Summary
discoverInheritedParallelSlotsiterated root-to-leaf but usedif (!slotMap.has(slot.name))which made the farthest ancestor's slot win instead of the closest@sidebarat bothapp/andapp/dashboard/, the route/dashboard/settingswould incorrectly get the root-level sidebarhas()guard soslotMap.set()is called unconditionally for inherited slots — since iteration goes root-to-leaf, later (closer) ancestors naturally overwrite earlier (farther) onesisOwnDirbranch which already used unconditionalset()Test plan
@sidebarat root and dashboard levels, verifies/dashboard/settingsgets the dashboard-level slot