Repository navigation
refactor(app): move the roster and local health state into hooks - #1772
Conversation
Nine App blocks become calls at their own lines: useRosterState, useRecentFolderMemory, useMachinesRef, useLocalHealth, useRosterError, useRefetchTimer, useRosterLoader and useRosterEvents. loadHealth keeps its [] deps and now awaits readBridgeHealth and readLocalHealth. The event stream reads takeNotificationTargetRef through a getter at event time; its deps are unchanged. APP_HOOK_CEILING is lowered to 90. Plan: .omo/plans/app-stores-split.md wave 8.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
|
Merge pass: this PR moves the roster loader, including the token-from-URL, authenticate and verifySourceBoot flows, and the event stream. Per AGENTS.md, this comment records the review that stands in for a full one. Review: a gate reviewer on a different model than the author's, plus the merge pass's own checks. No findings.
All required checks are green and no review thread is open. |
) Wave 9 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 #1772. This wave moves the pane lens and the split view out of `src/App.tsx` into two files. Each contiguous block becomes one hook called at that block's own line (rule R1), so hook order is unchanged. In particular, the `lastKeyAt` keydown capture listener still registers after the sidebar's Escape listener, and the split validation and drag-listener effects run where they did. ## What moves | Hook (file) | Block in App.tsx on `3a449c96c` | |---|---| | `useSplitRecheck()` (`useSplitView.ts`) | 256-258: `otherRecheck`, `otherRosterTick` | | `usePaneLensState()` (`usePaneLens.ts`) | 293-295: `lens`, `viewPicks` | | `useSplitState()` (`useSplitView.ts`) | 296-335: split state, `soloSlot`, `endSplit`, `splitRef`, `splitShownRef`, `lastKeyAtRef` and its listener, the drop preview state, `paneAreaRef`, `tabDrag` | | `usePaneLens({ … })` (`usePaneLens.ts`) | 578-595: `lenses`, `lensKey`, `notificationView`, the lens settled during render, the alert's lens override | | `usePaneViewPicks({ … })` (`usePaneLens.ts`) | 608-627: `pickView`, `setView` | | `useSplitLayout({ … })` (`useSplitView.ts`) | 632-791: the other half's derivation, the validation effect, `applySplit` / `activateSlot` / `closeSlot` / `selectInSlot` / `dockSide` / `dockAt`, the `onDrop` effect, the tab-drag effect, the drag handlers, the window drag listeners | **Unchanged structure:** - **Lens settled during render:** `usePaneLens` still calls `setLens` and `setTerminalPeek` during render. It runs on App's fiber, exactly as the inline code did. - **Plain functions:** the split's plain functions stay plain functions, not wrapped in `useCallback`. - **Render-time ref assignments:** `splitShownRef.current = splitOn` and the `otherTabRef` lines stay render-time. - **Dependency lists:** every dependency list is byte-identical. - **What stays in App:** `usePhoneSheetBack` for the peek stays in App at its line. Line 262 inside `rosterIn` also stays: it reads the ref and setter that `useSplitRecheck` returns. **Module-level helpers** move verbatim with their comments: `storedView` to `usePaneLens.ts`, and `SELECTION_KEY`, `StoredSelection`, `storedSelection` and `storeSelection` to `useSplitView.ts`. App imports back the ones it still calls. No copies are left behind. **Not purely moved code (type-only):** four `split!` non-null assertions in the pane-area JSX (`split!.active`, `split!.other.machineId`, `split!.other.paneId`, `slotSide(split!, slot)`). - **Why they're needed:** `splitOn` used to be computed in App, and its `split !== null` narrowed `split` for TypeScript in the JSX. Returned from the hook, it is a plain boolean, so the narrowing is gone. - **Why it's only types:** each site is reached only when `splitOn` (or `!active`) holds, so `split` is non-null there. The emitted JavaScript is unchanged. **Hook ceiling:** `APP_HOOK_CEILING` drops from 90 to 62. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 590 lines as moved. The other 108 lines are: - App's narrowed imports, the two new imports and the six calls; - the four `split!` lines; - the new files' imports, params types, signatures and returns; - the `export` keywords on the moved helpers; - the ceiling. - **Moved blocks are exact:** all six blocks above appear byte for byte in the new files. - **Positions:** the line before and after each call is the line that surrounded its block. Two pairs of blocks were adjacent, so their calls are adjacent too. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** **109 pass, 0 fail across 8 files**, from: `HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts scripts/conventions.test.ts src/lib/split.test.ts src/lib/paneLens.test.ts src/lib/terminalPeek.test.ts src/lib/panePresentation.test.ts src/lib/i18n.test.ts` - `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.8s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 1786 s), including the split view, header lens switch, default view, phone split grid, tab menu, notification view, pane find, render crash, terminal autoswitch and ui regressions. 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. Outside contributor PRs that touch `src/App.tsx` and will need a rebase: #1427. No changelog fragment: users see no change.
…1774) Wave 10, the last wave 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 #1773. This wave moves the selection, link landing, notification targets and the address bar out of `src/App.tsx` into two files. The selection code is interleaved with code that stays in App, such as `useSplitRecheck`, `useSidebarLayout`, `useScreenWakeLock` and the auth callbacks. So each contiguous block becomes one hook called at that block's own line (rule R1). Effect, layout-effect and listener order are unchanged. In particular: - The pane `popstate` listener still registers before the New-workspace dialog's `popstate` listener, which stays in App. - `selectionRef` is still marked in its `useLayoutEffect` at commit. ## What moves | Hook (file) | Block in App.tsx on `3f0cfcee8` | |---|---| | `useSelectedMachine` (`useSelection.ts`) | 158-163: `selectedMachineId`, `selectedMachine`, `snapshot` | | `useSelectionState` | 178-207: `selectedPaneId`, `notificationViewTarget`, `terminalPeek`/`endPeek`, `pendingLink`, `linkLanded`, `rosterSeq`/`linkSince`/`selectionSince`, `rosterTick`/`linkTick` | | `useLinkLanding` | 209-234: `rosterIn`, `pendingFile`, `selectionHint`, the header note and its timer, `note`, `autoSelected` | | `useSelectionMark` | 236-242: `selectionRef` and its layout effect | | `useSelectTarget` | 323-415: `selectedMachineRef`, `selectTarget` and its ref, the selection validation effect, the stored-selection effect | | `useSelectPane` | 417-424: `selectPane` | | `useNotificationTargets` | 428-449: `takeNotificationTarget`, its ref, the `onNotificationTarget` effect | | `useSelectedPane` | 452: `selectedPane` (`useScreenWakeLock` at 453 stays in App) | | `useSelectedLayout` | 454-472: `selectedWorkspace`, `selectedLayout`, `presentedPaneId`, the zoom-redirect layout effect | | `useAddressBar` (`useAddressBar.ts`) | 507-603: `writtenLink`, `poppedTo`, `newSessionOpenRef`, the link inputs, the file release effect, the URL-writing effect, the link's pending-file effect, the pane `popstate` effect | | `useMachineGone` (`useSelection.ts`) | 749-763: the removed-PC effect | **Unchanged:** - **Dependency lists:** every one is byte-identical. - **Render-time assignments:** `selectedMachineRef.current = …`, `selectTargetRef.current = …`, `takeNotificationTargetRef.current = …` and `newSessionOpenRef.current = …` stay render-time. - **Stored-selection helpers:** `storedSelection` and `storeSelection` are imported from `useSplitView.ts` (PR #1773), not copied. - **Follow-focus:** the block the plan listed here already moved, verbatim, with the event stream in PR #1772. **Hook ceiling:** `APP_HOOK_CEILING` drops from 62 to 24. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 671 lines as moved. The other 184 lines are: - App's narrowed imports, the two new imports and the eleven calls; - the new files' imports, params types, two local type aliases (`SelectionHint`, `SelectTarget`), signatures and returns; - the ceiling. - **Moved blocks are exact:** all eleven blocks above appear byte for byte in the new files. - **Positions:** the line before and after each call is the line that surrounded its block on main. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** **119 pass, 0 fail across 10 files**, from: `HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts scripts/conventions.test.ts src/lib/deepLink.test.ts src/lib/notificationTarget.test.ts src/lib/selectionMark.test.ts src/lib/followFocus.test.ts src/lib/sheetHistory.test.ts src/lib/settingsHistory.test.ts src/lib/i18n.test.ts` - `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.8s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 1801 s), including the deep link, notification startup and view, pending pane switch, machine dialog and conflict, file viewer Back/Forward, settings pages, sidebar activity, mobile tabs and ui regressions. 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. Outside contributor PRs that touch `src/App.tsx` and will need a rebase: #1427. No changelog fragment: users see no change.
Wave 8 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 #1771.This wave moves the PC roster and this PC's health state out of
src/App.tsxinto 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
58fcc3ae4useRosterState()(useMachineRoster.ts)machines,machineRosterLoadeduseRecentFolderMemory({ machines })useMachinesRef({ machines })machinesRefand its render-time assignmentuseLocalHealth()(useLocalHealth.ts)localHealth,health,localFreshness,shownHealthuseRosterError()erroruseRefetchTimer()refetchTimeruseRosterLoader({ … })snapshotRequests,loadRef,reorderCoordinator,load, the polling effect,scheduleRefetch, the refetch cleanupuseRosterEvents({ … })Module-level helpers move with the code that uses them, verbatim with their comments:
sameData(exported, becauseuseLocalHealth.tsimports it);POLL_MS;REFETCH_DEBOUNCE_MS.Not purely moved code, three spots:
loadHealth: the local health read inside it (7 lines) becomesreadLocalHealth, auseCallback(..., [])inuseLocalHealth. Its body is those lines verbatim, and it uses only refs and a setter.loadHealthis nowawait readBridgeHealth(); await readLocalHealth();, with its dependency list still[].loadHealthkeeps its identity and runs the same code. The polling effect,unlockandlockdepend on that identity.takeNotificationTargetRef, which App declares further down. SouseRosterEventstakesgetTakeNotificationTargetRef: () => 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.[locked, scheduleRefetch, dropIn, chime, reorderCoordinator]is unchanged, so the stream resubscribes exactly when it did before.Departures from the plan's draft:
onPaneFocused. Every value it reads is declared above the effect, so it moves as-is.useSessionHistoryList.Hook ceiling:
APP_HOOK_CEILINGdrops from 107 to 90.Checks
--color-moved:git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEADshows 374 lines as moved. The other 105 lines are:loadHealthand thegetTakeNotificationTargetRefargument;readLocalHealthwrapper, the getter line and the returns;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 typecheckpasses.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.tsbun 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 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.