Repository navigation
refactor(terminal): move the terminal's mount effect into a hook - #1758
Merged
Merged
Conversation
Move the terminal's mount effect (new Terminal, the socket and session wiring, input and touch handlers) verbatim into useTerminalMount, and the shared constants into paneTerminalShared. PaneTerminal calls the hook at the position of the old effect, so effect order is unchanged. Pin (b) now looks for the useTerminalMount( call before the attach reset; i18n PART_FILES and the IME diagnostic's module id follow the moved code. Plan: .omo/plans/paneterminal-split.md PR1.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Owner
Author
|
Merge pass: move-only PR (PaneTerminal split, PR 1). As AGENTS.md allows, it is merged on its checks without waiting for a CodeRabbit review.
All required checks are green and no review thread is open. |
devswha
added a commit
that referenced
this pull request
Oct 23, 2026
… sends into hooks (#1764) PR 2 of the PaneTerminal.tsx split. The plan is `.omo/plans/paneterminal-split.md` in the maintainer's workspace, and plan-reviewer approved it. It follows PR #1758, which moved the mount effect. This PR moves four blocks out of `src/components/PaneTerminal.tsx` into four hooks. Each block moves as one unchanged span. Each hook is called at the exact line its block occupied, so hook order, effect order and cleanup order stay as they are. Every effect keeps its dependency list, and every callback keeps its `useCallback` dependencies. `src/components/PaneTerminal.tsx` goes from 1,967 to 1,477 lines. ## What moves | Hook | Block | Deps | Returns | |---|---|---|---| | `src/lib/useTerminalRefits.ts` | the six theme, font and fit effects (133 lines) | 27 | nothing | | `src/lib/usePaneAttach.ts` | the reset layout effect on a pane or terminal replacement (`[paneId, terminalId]`) and the two one-line effects after it (80 lines) | 50 | nothing | | `src/lib/useTerminalSends.ts` | the send callbacks and the direct-typing effect (144 lines) | 37 | `sendDraft`, `discardDraft`, `submitComposerMessage`, `sendComposerText`, `sendTerminalLine`, `reassertGrid`, `pressEnter`, `toggleDirect` | | `src/lib/useComposerSends.ts` | `composerSend` and `actOnPending` (138 lines) | 29 | `composerSend`, `actOnPending` | - **The hooks:** each follows `useTerminalMount`'s pattern. A `<Name>Deps` interface lists every name the block reads from the component, each typed as the component declares it, and the hook destructures it on its first line. A missed name would be a type error. - **Call order in `PaneTerminal.tsx`:** `useTerminalMount`, then `useTerminalRefits`, then `usePaneAttach`. Further down, where their blocks stood, come `useTerminalSends` and `useComposerSends`. `usePaneLane(stackRef)` does not move. - **Order pin:** `src/conventions.test.ts` used to check that the mount hook comes before the attach reset effect, found via `}, [paneId, terminalId]);`. That effect now lives in `usePaneAttach`, so the pin checks that `useTerminalMount(` comes before `usePaneAttach(`. Swapping the two calls fails it. - **`src/lib/i18n.test.ts`:** `PART_FILES.terminal` gains `lib/useComposerSends.ts`, because the moved callbacks' `t()` keys belong to the terminal part. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 1,009 lines as moved. The other 229 lines are: - PaneTerminal.tsx's narrowed imports, the four new imports and the four call lines; - the new files' imports, the four `Deps` interfaces (143 field lines), signatures, destructuring lines and returns; - the pin's two-line adaptation and the `PART_FILES` entry. - **Moved blocks are exact:** each original span (lines 797-929, 931-1010, 1070-1213 and 1386-1523 of `PaneTerminal.tsx` on `e3aec1528`) appears byte for byte inside its hook. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** `HERDR_TEST_MODE=unit bun test src/conventions.test.ts src/lib/i18n.test.ts src/lib/settings.test.ts scripts/conventions.test.ts`: 117 pass, 0 fail. - `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 61.1s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 2085 s), run on this commit before its rebase onto the latest main (which changed only `src/App.tsx`, `src/app-hooks.test.ts` and server files). The integration lane had three 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 two in `server/gjc.contract.test.ts` ("binds same-cwd panes independently by native PID…", "falls back to scrollback when the native GJC binding is missing": `pane.process_info` did not yet list the isolated GJC process while another lane ran beside it). Rerun alone, `server/gjc.contract.test.ts` passes. 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/components/PaneTerminal.tsx`: #1639. `git merge-tree` shows it still merges cleanly with both main and this branch. The moved blocks include the attach reset, the queued-input sends and the pending-message actions. A code-review agent's stand-in review may be wanted before the merge. Move-only: moved blocks plus imports, deps interfaces, four calls, the adapted order pin and one `PART_FILES` entry. No changelog fragment: users see no change.
devswha
added a commit
that referenced
this pull request
Oct 23, 2026
…1767) PR 3 of 3 of the PaneTerminal.tsx split. The plan is `.omo/plans/paneterminal-split.md` in the maintainer's workspace, and plan-reviewer approved it. It follows PR #1758 and PR #1764. This PR moves the chat lens's terminal logic out of `src/components/PaneTerminal.tsx` into three hooks. Each block moves as one unchanged span. Effects keep their dependency lists, and callbacks keep their `useCallback` dependencies. `src/components/PaneTerminal.tsx` goes from 1,477 to 1,174 lines. Over the three PRs it went from 3,665. ## What moves | Hook | Block | Deps | Returns | Called | |---|---|---|---|---| | `src/lib/usePeekReturn.ts` | after a peek: the manual-peek and auto-return state, the still-open note, the input-row frame watch, and the peek-end layout effect (153 lines) | 29 | 12 names | where the block stood | | `src/lib/useChatCallbacks.ts` | the chat lens's callbacks and state: conversation watch, terminal output, sent and metadata, greeting room, prompt, suggestion, restore and pending answer (90 lines) | 12 | 28 names | where the block stood, right after `usePeekReturn` | | `src/lib/useTypedKeys.ts` | the key bar's `pressKey` and `toggleModifier` (30 lines), and Hermes' one-Ctrl+C stop guard with `abortTurn` (34 lines) | 16 | `pressKey`, `toggleModifier`, `abortTurn` | where the stop block stood | ### Hook and effect order - **`useTypedKeys`:** the key-bar callbacks used to sit about 15 lines above the stop block. They have no effects, and only JSX reads them, so creating them a few hooks later changes nothing. Nothing between the two old positions reads them. - **`usePeekReturn` and `useChatCallbacks`:** each sits exactly where its block was, so their effects run in the same order as before. ### Other changes - **`StillOpen`:** this was a local type alias inside the component. Two hooks now use it, so it moves to `src/lib/paneTerminalShared.ts` as an exported type. Types have no runtime effect. - **`src/lib/i18n.test.ts`:** `PART_FILES.terminal` gains `lib/usePeekReturn.ts` and `lib/useTypedKeys.ts`, because their `t()` keys belong to the terminal part. - **Imports:** `PaneTerminal.tsx` drops the imports only the moved code used. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows 629 lines as moved. The other 116 lines are: - `PaneTerminal.tsx`'s narrowed imports, the three new imports and the three calls; - the hooks' imports, three `Deps` interfaces (57 field lines), signatures, destructuring lines and returns; - the `StillOpen` type's move; - the two `PART_FILES` entries. - **Moved blocks are exact:** lines 646-735, 819-848 and 863-896 of `PaneTerminal.tsx` on `2fa93ab49` appear byte for byte in their hooks. Lines 493-645 do too, apart from the one `StillOpen` line. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** `HERDR_TEST_MODE=unit bun test src/conventions.test.ts src/lib/i18n.test.ts src/lib/settings.test.ts scripts/conventions.test.ts src/lib/terminalPeek.test.ts src/lib/keyBar.test.ts src/lib/hermesStop.test.ts`: 163 pass, 0 fail. - `bun run check fast`: passes after the rebase (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.5s) - **`bun run check integration browser`:** the browser lane exits 0 (every browser script passed, 1895 s), run on this commit before its rebase onto the latest main (which changed only `src/App.tsx`, `src/app-hooks.test.ts`, `src/lib/useSidebarLayout.ts` and server files). The integration lane's only failure is `server/api.contract.test.ts` "creates, edits, searches, inspects, and closes an owned workspace" (line 1540, `/api/pane/files` returns `[]`), which fails the same way on unchanged `origin/main` on this PC. 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/components/PaneTerminal.tsx`: #1639. It already conflicts with main (`src/lib/i18n.ja.ts`, `src/lib/i18n.ko.ts`, `src/lib/i18n.zh.ts`) and needs a rebase either way; against this branch it conflicts in `src/components/PaneTerminal.tsx`, `src/lib/i18n.ja.ts`, `src/lib/i18n.ko.ts`, `src/lib/i18n.zh.ts`. The moved blocks include the queued-input stop path, Hermes' stop guard and the peek's auto-return. A code-review agent's stand-in review may be wanted before the merge. Move-only: moved blocks plus imports, deps interfaces, three calls, one shared type and two `PART_FILES` entries. No changelog fragment: users see no change.
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.
PR 1 of the PaneTerminal.tsx split. The plan is
.omo/plans/paneterminal-split.mdin the maintainer's workspace, and plan-reviewer approved it.This PR moves the terminal's mount effect out of
src/components/PaneTerminal.tsxinto one hook, as one unchanged block. The hook is called at the same place in the component, so hook order, effect order, listener registration order and the cleanup order stay as they are. The effect still has[]dependencies and still captures the first render's values, exactly as before.src/components/PaneTerminal.tsxgoes from 3,665 to 1,966 lines.Two commits: the pins first, then the move
test(terminal): pin scrollback 0 and the mount-before-reset order before the splitadds a describe block tosrc/conventions.test.ts, written against the unchanged code:new Terminal({insrc/setsscrollback: 0, wherever that code lives (the AGENTS.md trap);PaneTerminal.tsx, the mount effect comes before the attach reset effect (the one with[paneId, terminalId]).Both pass on unchanged code. Removing
scrollback: 0fails (a), and moving the reset above the mount fails (b).refactor(terminal): move the terminal's mount effect into a hookuseLayoutEffectmoves, unchanged, intosrc/lib/useTerminalMount.ts. That is old lines 835-2494: xterm setup, IME, selection and copy, output and OSC handling, the attach stream, input and paste, resize/touch/pinch, and the lifecycle and cleanup.__HERDR_TEST_HOOKS__declaration, which only this effect reads; itstypeofguard keeps the Bun.build fixture working.useTerminalMount(deps: TerminalMountDeps)destructures its deps and runs the block. The interface lists exactly the 105 names the effect reads from the component (69 refs, 26 setters and callbacks, 10 values), each typed as the component declares it. A missed name would be a type error.RESIZE_SETTLE_MS,RELEASE_AFTER_MS,inUse,connectedSocketsandplainErrormove verbatim, now exported, intosrc/lib/paneTerminalShared.ts. Both the hook and the code that stays use them.PaneTerminal.tsx: oneuseTerminalMount({ … })call where the block stood, afternoteClipboardand before the theme effect.usePaneLane(stackRef)stays, assrc/lib/settings.test.tsrequires.useTerminalMount(comes before the attach reset. Moving the call below the reset fails it.src/lib/i18n.test.ts:PART_FILES.terminalgainslib/useTerminalMount.ts, because the moved effect'st()keys belong to the terminal part.scripts/terminal-ime-diagnostic.ts: this manual tool patches theonDataanchor, which now lives in the hook, so it matches/src/lib/useTerminalMount.tsinstead of/src/components/PaneTerminal.tsx.Checks
--color-moved:git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEADshows 3,375 lines as moved. The other 174 lines are:exportdeclarations and the 5 originals they replace;diffof old lines 835-2494 against the hook body is empty.bun run typecheckpasses.HERDR_TEST_MODE=unit bun test src/conventions.test.ts src/lib/i18n.test.ts src/lib/settings.test.tsall pass.bun run check integration browserpasses, exit 0. That includes:__HERDR_TEST_HOOKS__guard moved intact.origin/mainon this PC. That test isserver/api.contract.test.ts"workspace and discovery endpoints > creates, edits, searches, inspects, and closes an owned workspace", line 1540, where/api/pane/filesreturns[]for the mention file. This PR changes no server code. CI's integration lane runs it in its own environment.bun run check fast: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 58.1s)Outside PRs that touch the same files
No other maintainer PR touches these files. One outside contributor's PR touches
src/components/PaneTerminal.tsx: #1639.git merge-treeshows it merges cleanly with both main and this branch.The move touches the attach, observe and queued-input lines, so a code-review agent's stand-in review may be wanted before the merge.
Move-only: moved code plus imports, exports, the deps interface, one call, the pins and their adaptation, one
PART_FILESentry and one diagnostic module id. No changelog fragment: users see no change.