Repository navigation
refactor(app): move the access state into a hook - #1771
Conversation
The access state and lockedRef move into src/lib/useAccess.ts, each called at its own line. loadHealth's bridge-health read becomes readBridgeHealth, a []-callback, with loadHealth's deps unchanged. The hook-call ceiling is lowered to 107. Plan .omo/plans/app-stores-split.md wave 7.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
|
Merge pass: this PR touches authentication state, so per AGENTS.md this comment records the review that stands in for a full one. Reviews: a gate reviewer on a different model than the author's, plus my own checks. Findings: none.
All required checks are green and no review thread is open. |
Wave 8 of the App.tsx split. The plan is `.omo/plans/app-stores-split.md` in the maintainer's workspace, and plan-reviewer approved it. It follows PR #1771. This wave moves the PC roster and this PC's health state out of `src/App.tsx` into two files. Each contiguous block becomes one hook called at that block's own line (rule R1), so effect order is unchanged. In order, that is the recent-folders effect, then polling, then the event stream, as before. ## What moves | Hook (file) | Block in App.tsx on `58fcc3ae4` | |---|---| | `useRosterState()` (`useMachineRoster.ts`) | 213-214: `machines`, `machineRosterLoaded` | | `useRecentFolderMemory({ machines })` | 224-236: the recent-folders effect | | `useMachinesRef({ machines })` | 243: `machinesRef` and its render-time assignment | | `useLocalHealth()` (`useLocalHealth.ts`) | 247-255: the health book, reads, `localHealth`, `health`, `localFreshness`, `shownHealth` | | `useRosterError()` | 256: `error` | | `useRefetchTimer()` | 398: `refetchTimer` | | `useRosterLoader({ … })` | 412-478: `snapshotRequests`, `loadRef`, `reorderCoordinator`, `load`, the polling effect, `scheduleRefetch`, the refetch cleanup | | `useRosterEvents({ … })` | 482-547: the event-stream effect | Module-level helpers move with the code that uses them, verbatim with their comments: - `sameData` (exported, because `useLocalHealth.ts` imports it); - `POLL_MS`; - `REFETCH_DEBOUNCE_MS`. **Not purely moved code, three spots:** - **`loadHealth`:** the local health read inside it (7 lines) becomes `readLocalHealth`, a `useCallback(..., [])` in `useLocalHealth`. Its body is those lines verbatim, and it uses only refs and a setter. - `loadHealth` is now `await readBridgeHealth(); await readLocalHealth();`, with its dependency list still `[]`. - Both callbacks are stable, so `loadHealth` keeps its identity and runs the same code. The polling effect, `unlock` and `lock` depend on that identity. - **The event stream:** it reads `takeNotificationTargetRef`, which App declares further down. So `useRosterEvents` takes `getTakeNotificationTargetRef: () => takeNotificationTargetRef`, and the one added line, `const takeNotificationTargetRef = getTakeNotificationTargetRef();`, opens the message handler. Every other line of the effect is unchanged, and the ref is still read when an event arrives. - **The effect's dependency list:** `[locked, scheduleRefetch, dropIn, chime, reorderCoordinator]` is unchanged, so the stream resubscribes exactly when it did before. **Departures from the plan's draft:** - The follow-herdr-focus block stays inside the event-stream effect verbatim, instead of becoming an injected `onPaneFocused`. Every value it reads is declared above the effect, so it moves as-is. - The plan's "probe forgetting" item already moved in wave 6, inside `useSessionHistoryList`. **Hook ceiling:** `APP_HOOK_CEILING` drops from 107 to 90. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 374 lines as moved. The other 105 lines are: - App's narrowed imports, the two new imports and the eight calls; - the two lines of `loadHealth` and the `getTakeNotificationTargetRef` argument; - the new files' imports, params types, signatures, the `readLocalHealth` wrapper, the getter line and the returns; - the ceiling. - **Moved blocks are exact:** every block above, and the health-read lines 404-410, appear byte for byte in the new files. The event-stream block does too, apart from the one getter line. - **Positions:** the line before and after each call is the line that surrounded its block. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** **120 pass, 0 fail across 11 files**, from: `HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/healthPresentation.test.ts src/lib/snapshotRequests.test.ts src/lib/workspaceOrder.test.ts src/lib/eventStream.test.ts src/lib/snapshot.test.ts src/lib/recent-directories.test.ts src/lib/preferencesSync.test.ts src/lib/i18n.test.ts scripts/conventions.test.ts` - `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.9s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 1800 s), including the machines, machine conflict and dialog, sidebar machine layout/removal, workspace rows and touch reorder, recent folders, preferences sync, sidebar activity, session history, follow-focus, health-flap, herdr-restart and pending pane switch scripts. The integration lane's only failure is `server/api.contract.test.ts` "creates, edits, searches, inspects, and closes an owned workspace" (line 1540), which fails the same way on unchanged `origin/main` on this PC; CI runs that lane in its own environment. ## Outside PRs that touch the same files No other maintainer PR touches these files. One outside contributor's PR touches `src/App.tsx`: #1427. It already conflicts with main, and needs a rebase either way. No changelog fragment: users see no change.
Wave 7 of the App.tsx split. The plan is
.omo/plans/app-stores-split.mdin the maintainer's workspace, and plan-reviewer approved it. It follows PR #1770.This wave moves the access state out of
src/App.tsxintosrc/lib/useAccess.ts, as two hooks. Each is called at its own block's line, per the plan's rule R1:useAccessState(), where the access state stood:locked,lockReason,pairCode,auth,canSignOutandpairedFromAddress, with their comments.pairCode's initializer still runstakePairCode()at the same point in App's render.readBridgeHealth: the bridge-health read that openedloadHealth, now auseCallback(..., []). Its body is the original two lines (thefetchBridgeHealth()try and its catch), and it uses only stable setters.useLockedRef({ locked }), wherelockedRefstood. It returns the same ref object, with the render-time assignment.Not purely moved code: in
loadHealth, the two bridge-health lines becomeawait readBridgeHealth();.loadHealth's dependency list stays[].readBridgeHealthis stable, so the closureloadHealthholds from the first render runs the same code as before.loadHealth's identity, which the polling effect andunlock/lockdepend on, is unchanged.Stays in App, as the plan says:
unlock;lock.Hook ceiling:
APP_HOOK_CEILINGdrops from 113 to 107, after moving fouruseStateand twouseRefcalls.Checks
--color-moved:git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEADshows 30 lines as moved. The other 26 lines are:await readBridgeHealth();line;readBridgeHealthwrapper lines and the returns;App.tsxon705dcb8ffbyte for byte, at lines 257-267, 403-404 and 413-414.bun run typecheckpasses.HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/authLink.test.ts src/lib/phone.test.ts src/lib/i18n.test.ts: 41 pass, 0 fail.const zz = useState(false);to App.tsx makessrc/app-hooks.test.tsfail.bun run check fast: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.9s)bun run check integration browser: the browser lane exits 0 (every browser script passed, 1795 s), including the access gate and sign-out checks in ui-regression, herdr profiles, and every script that loads through the gate. The integration lane's only failure isserver/api.contract.test.ts"creates, edits, searches, inspects, and closes an owned workspace" (line 1540), which fails the same way on unchangedorigin/mainon this PC; CI runs that lane in its own environment.Outside PRs that touch the same files
No other maintainer PR touches these files. One outside contributor's PR touches
src/App.tsx: #1427. It already conflicts with main, and needs a rebase either way.No changelog fragment: users see no change.