Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getEntryOffset() fell through to set offset = state[i].length - 1 when the target view was not found in the current history state. For a single-entry state this returned 0, causing navigate() to call navigateBack(0) which always calls replaceState instead of pushState. Returning -1 from the fallthrough case correctly signals that the target is not in history, so navigate() takes the pushState branch. Adds a test: two URL siblings in a shared stack — navigating A→B pushes a new history entry and back() returns to A.
|
Thanks for digging into this and for the clear write-up! But this is intended behavior. Views that aren't in a parent/child relationship replace the history entry. Only views listed in the current view's You can see it in the existing "uses push navigation to view with multiple parents" test, which this PR had to change from If you want B to be pushed when you navigate from A, add it to A's stack: |
|
Thanks so much for the quick reply, keep up the great work! |
Hey! Long time user, first time patcher? Hope this is right and I'm not just setting my views up wrong!
Problem
Navigating between sibling views (views that share a parent stack but are not in a parent/child relationship) always replaces the current history entry instead of pushing a new one. The browser back button skips over all sibling navigation.
Root cause
In getEntryOffset(), when the target view is not found anywhere in the current history state, the loop falls through to:
For a single-entry state this sets offset = 0. navigate() then calls navigateBack(0, ...), which always calls replaceState when state.length === 1.
Fix
Return -1 from the fallthrough case. This signals to navigate() that the target is not in history, so it takes the pushState branch.
Test
Added a standalone test: two URL siblings in a shared stack — navigating A→B pushes a new history entry and history.back() returns to A.
Passing locally: