fix: navigational dropdown back button bug#322
Merged
dedarritchon merged 7 commits intomainfrom Mar 26, 2026
Merged
Conversation
cmp831
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Navigational Dropdown was presenting some buggy behavior, needing to click the back button twice to go back in some situations.
Cause
The old logic reset the stack when
contentVersionchanged but scheduled the auto-restore path by callingsetAutoNavigateToSubmenuPathfrom inside thesetViewStackfunctional updater. That’s nested state updates in one updater, which is easy to get wrong and can leave stack vs. path briefly inconsistent for children (e.g. submenu triggers firing auto-navigateTo at the wrong time). The “if top id === id, replace instead of push” block was papering over duplicate stack entries from that kind of race.What we changed
viewStackRef
On each render, viewStackRef.current is set to the latest viewStack, so the layout effect can read the pre-reset stack reliably on the render where contentVersion just changed.
contentVersion useLayoutEffect
When the version actually changes (same guard as before with prevContentVersionRef):
Derive
navigationPathfromviewStackRef.current(slice of submenu ids after root).Call
setViewStack([root])as a normal update.If there is a path to restore, call s
etAutoNavigateToSubmenuPath(navigationPath)as a separate update, not from inside the stack updater.So the fix is structural: same behavior intent, but without nesting one setter inside the other.
navigateTo when top.id === id
That branch stayed, but the idea is reframed: idempotent navigation to the current top view (updates getContent / parentTitle, avoids pushing another frame for the same id). It’s not framed as “contentVersion ran twice” anymore.