Skip to content

fix: navigational dropdown back button bug#322

Merged
dedarritchon merged 7 commits intomainfrom
fix/navigational-dropdown-bug
Mar 26, 2026
Merged

fix: navigational dropdown back button bug#322
dedarritchon merged 7 commits intomainfrom
fix/navigational-dropdown-bug

Conversation

@dedarritchon
Copy link
Copy Markdown
Contributor

@dedarritchon dedarritchon commented Mar 26, 2026

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 contentVersion changed but scheduled the auto-restore path by calling setAutoNavigateToSubmenuPath from inside the setViewStack functional 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 navigationPath from viewStackRef.current (slice of submenu ids after root).
Call setViewStack([root]) as a normal update.
If there is a path to restore, call setAutoNavigateToSubmenuPath(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.

@dedarritchon dedarritchon requested a review from a team March 26, 2026 15:38
@dedarritchon dedarritchon merged commit 0d91891 into main Mar 26, 2026
5 checks passed
@dedarritchon dedarritchon deleted the fix/navigational-dropdown-bug branch March 26, 2026 18:10
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.

2 participants