Repository navigation
refactor(app): move the connection chip state into a hook - #1762
Conversation
The chip state and paneLost, and the server-message callback, move verbatim into src/lib/useConnectionChip.ts as two hooks, called where each block stood in App.tsx. App hook ceiling lowered from 176 to 171. Plan .omo/plans/app-stores-split.md wave 3.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
|
Merge pass: move-only PR (wave 3 of the App.tsx split). As AGENTS.md allows, it is merged on its checks without waiting for a CodeRabbit review. Line-multiset comparison: the only differences are the narrowed type import, the new import, the two calls, the ceiling and the new file's wrapper lines. A gate reviewer on a different model than the author's confirmed:
The ceiling test and the typecheck pass. The PR's browser lane ran green locally ( All required checks are green and no review thread is open. |
…1766) Wave 4 of the App.tsx split. The plan is `.omo/plans/app-stores-split.md` in the maintainer's workspace. It follows PR #1762. This wave moves the drawer, sidebar and file-panel layout state out of `src/App.tsx` into `src/lib/useSidebarLayout.ts`. The hook runs inside App's render, so updates and effect order are unchanged. ## What changes Three blocks move verbatim, in their order, into `useSidebarLayout({ initialLink })`: 1. **Drawer:** the drawer state (a link can open it), `drawerOpenRef`, `wideScreen`, and the effect that closes the drawer on a wide window. 2. **Gestures:** the edge-swipe effect and the Escape capture listener that puts the drawer away. 3. **Widths:** `sidebarCollapsed`, `sidebarWidth`, `filePanelAvailable` and `filePanelWidth`. The hook returns those values, their setters, and the same `drawerOpenRef` object. **What stays in `App.tsx`:** - One call at the first block's position. - `selectionRef` and its layout effect, which sat between the blocks but belong to selection. They now follow the call directly. - Every call site. **Listener order:** the `lastKeyAt` keydown listener still comes after the call, so the Escape capture listener still registers first. **Imports:** `storedSidebarWidth`, `FILE_PANEL_DOCK_QUERY`, `storedFilePanelWidth` and `watchDrawerSwipe` leave App's imports. **Hook ceiling:** `APP_HOOK_CEILING` drops from 171 to 163, after moving four `useState`, one `useRef` and three `useEffect` calls. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 56 lines as moved. The other 22 lines are: - App's removed imports and the new import; - the call line; - the ceiling value; - the new file's imports, params type, signature, doc comment and return. - **Moved blocks are exact:** each block (lines 365-371, 379-393 and 394-399 of `App.tsx` on `e44fc9f8f`) appears byte for byte in the hook. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** `HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/lib/edgeSwipe.test.ts src/lib/sidebarWidth.test.ts src/lib/filePanelWidth.test.ts src/conventions.test.ts`: 45 pass, 0 fail. - **Ceiling test:** adding `const zz = useState(false);` to App.tsx makes it fail. - `bun run check fast`: passes after the rebase (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.6s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 2036 s), run on this commit before its rebase onto the latest main (which changed only PaneTerminal and server files). The integration lane had two failures, none in code this PR touches: `server/api.contract.test.ts` "creates, edits, searches, inspects, and closes an owned workspace" (line 1540, fails the same way on unchanged `origin/main` on this PC) and `server/gjc.contract.test.ts` "binds same-cwd panes independently by native PID…" (`pane.process_info` did not yet list the isolated GJC process while other lanes ran on the same PC); rerun alone on this branch, `server/gjc.contract.test.ts` passes (10 pass, 0 fail). CI runs the integration 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 in `App.tsx`, and needs a rebase either way. Move-only: moved lines plus imports, the hook signature and return, one call and the lowered ceiling. No changelog fragment: users see no change.
Wave 3 of the App.tsx split. The plan is
.omo/plans/app-stores-split.mdin the maintainer's workspace. It follows PR #1757.This wave moves the connection chip's state out of
src/App.tsxintosrc/lib/useConnectionChip.ts, along with the callback that reads output stalls from server messages. Both hooks run inside App's render, so updates and effect order are unchanged.What changes
Moved verbatim into two hooks:
useConnectionChip()holds theconnected,connectedBeforeandoutputStoppedstates and thepaneLostcallback, with their comments. It returns all seven names App uses.useServerMessageHandler(setOutputStopped)holds thehandleServerMessagecallback with its[]dependency list.Stays in
App.tsx: each block becomes one call at its own former position:sessionHistorystate and the notifications state.enableNotifications.connWordand the inlineonConnectionChangelambda also stay in App.Imports:
ServerMessageleaves App's../shared/protocol.tstype import, because only the moved callback used it.Hook ceiling:
APP_HOOK_CEILINGinsrc/app-hooks.test.tsdrops from 176 to 171. That is App's new count, after moving threeuseStateand twouseCallbackcalls.Checks
--color-moved:git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEADshows 20 lines as moved. The other 19 lines are:bun run typecheckpasses.HERDR_TEST_MODE=unit bun test src/app-hooks.test.tspasses. Addingconst zz = useState(false);to App.tsx makes it fail.bun run check integration browser: browser lane exit 0 (every browser script passed, 1990 s). The integration lane's only failure isserver/api.contract.test.ts"creates, edits, searches, inspects, and closes an owned workspace" (line 1540,/api/pane/filesreturns[]), which fails the same way on unchangedorigin/mainon this PC; this PR changes no server code, and CI runs that lane in its own environment.bun run check fast: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 78.6s)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 inApp.tsx, and conflicts the same way with this branch, so it needs a rebase either way.Move-only: moved lines plus imports, two hook signatures, two calls and the lowered ceiling. No changelog fragment: users see no change.