refactor(router): one nav-tree model - #29610
Draft
chrisnojima wants to merge 1 commit into
Draft
Conversation
chrisnojima
added this pull request to stack #29615
September 9, 2026 19:40
The navigation tree shape - routes[0] of the root stack is the 'loggedIn' tab
navigator, routes[1..] holds modals and phone-pushed screens - was re-derived by
hand in eight functions across constants/router and router-v2/linking, and had
already drifted: navToThread's phone branch omitted the `index: 0` that
makeChatConversationState set on the loggedIn child state.
constants/nav-tree owns the shape now. Readers (visiblePath, visibleScreen,
modalStack, activeStack, currentTab, tabNavigatorState, isLoggedIn) are pure
functions of a NavState; builders (tabState, modalState, pushedAboveTabs)
return a PartialNavState. The modal-name registry and tabRoots live there too,
so modal-ness-by-name and tab roots are stated once. No navigationRef, no
dispatch, no chat.
Two literal differences were resolved in favour of one shape:
- `index: 0` on the loggedIn child state is now always spelled out. It is what
react-navigation computes anyway (a tab router rehydrates a missing index to
0), but a stack router rehydrates a missing index to the LAST route, so
leaving it off means the same omission reads differently at different depths.
- the tab-root route under a pushed screen now carries no `params`, matching
what the fs deep link already built. chatRoot declares `initialParams: {}`, so
StackRouter rehydrates `{...{}, ...undefined}` to the same `{}` the old
`params: {}` produced.
The store's `navState?: unknown` is typed by NavState, which removes the casts
at its three read sites.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rccpV5nLxxC5opF5xzrz7
chrisnojima
force-pushed
the
nojima/HOTPOT-arch-06-nav-tree
branch
from
September 11, 2026 01:47
77849d6 to
9249e64
Compare
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.
Problem
The navigation tree shape —
root.routes[0] === 'loggedIn'→ tab navigator → per-tab stack, withroot.routes[1..]holding modals and phone-pushed screens — was re-derived by hand in eight functions across two modules.constants/router.tsx:872androuter-v2/linking.tsx:53built literally the same phone nav-state object — and had already drifted: linking setindex: 0on theloggedInchild state,navToThreadomitted it.router-v2/linking-state.test.tsadmitted the duplication in a comment:— a test working around a missing module rather than testing one.
Change
New
constants/nav-tree.tsx, dependency-free (one runtime import, a zero-import leaf; everything elseimport type):visiblePath/visibleScreen/modalStack/activeStack/currentTab/isLoggedIn/tabNavigatorStatetabState/modalState/pushedAboveTabssetModalRouteNamesregistry andtabRootsPure functions over a plain
NavState. NonavigationRef, no dispatch, no chat imports.Also types
stores/router.tsx'snavState?: unknownasNavState, killing the casts infs/common/daemon.tsx,chat/inbox-and-conversation-shared.tsxandconstants/init/shared.tsx.Drift resolved
index: 0is now always spelled out. The two routers disagree on a missing index:SwitchRouter.getRehydratedState→state.routes[state.index ?? 0]— defaults to 0StackRouter.getRehydratedState→state.index ?? routes.length - 1— defaults to lastFor a one-route tab state both agreed, so the historical drift was benign — but the same omission reads differently at other depths, so the explicit form wins.
Second drift found while unifying:
navToThreademitted{name: 'chatRoot', params: {}}where the fs deep link emitted{name: 'fsRoot'}. The builder now omitsparams; sincechatRootdeclaresinitialParams: {},StackRoutercomputes the same{}either way.Validation
lint:allclean —0 bailed out, 0 whole-props deps, tsc clean both projects.jest --runInBand— 230 suites / 2251 tests (baseline 230 / 2236).constants/tests/router-visible.test.ts→nav-tree.test.ts, 5 → 20 tests; the builders were untested before.