Skip to content

refactor(app): move the connection chip state into a hook - #1762

Merged
devswha merged 1 commit into
mainfrom
refactor/app-connection-chip-hook
Oct 23, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/app-connection-chip-hook

Conversation

@devswha

@devswha devswha commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Wave 3 of the App.tsx split. The plan is .omo/plans/app-stores-split.md in the maintainer's workspace. It follows PR #1757.

This wave moves the connection chip's state out of src/App.tsx into src/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 the connected, connectedBefore and outputStopped states and the paneLost callback, with their comments. It returns all seven names App uses.
    • useServerMessageHandler(setOutputStopped) holds the handleServerMessage callback with its [] dependency list.
  • Stays in App.tsx: each block becomes one call at its own former position:

    • The first sits between the sessionHistory state and the notifications state.
    • The second sits right after the event-stream effect, before enableNotifications.

    connWord and the inline onConnectionChange lambda also stay in App.

  • Imports: ServerMessage leaves App's ../shared/protocol.ts type import, because only the moved callback used it.

  • Hook ceiling: APP_HOOK_CEILING in src/app-hooks.test.ts drops from 176 to 171. That is App's new count, after moving three useState and two useCallback calls.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD shows 20 lines as moved. The other 19 lines are:
    • the narrowed type import;
    • the new import;
    • the two call lines;
    • the ceiling value;
    • the new file's imports, doc comments, signatures and returns.
  • Typecheck: bun run typecheck passes.
  • Ceiling test: HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts passes. Adding const zz = useState(false); to App.tsx makes it fail.
  • Browser lane: bun run check integration browser: browser lane exit 0 (every browser script passed, 1990 s). 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; 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 in App.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.

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.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between d736944 and 2099622.

📒 Files selected for processing: 3
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/useConnectionChip.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Refactor
    • Connection status and stalled-output indicators continue to reflect connection changes, lost panes, and server-reported output stalls. Their handling has been streamlined without changing available controls or capabilities. No new user-facing features or behavior changes are included in this update.

App now uses hooks for connection state and stalled-output message handling. The hook-call test ceiling decreases from 176 to 171.

Changes: Connection state handling

Layer / File(s) Summary
Connection and message hooks
src/lib/useConnectionChip.ts
Added hooks for connection state, pane loss, and handling output_stalled error messages.
App integration and hook-call limit
src/App.tsx, src/app-hooks.test.ts
App uses the hooks instead of inline state and message handling. The hook-call test limit decreases from 176 to 171.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

  • devswha/ovis#1757: Moves layout-notice state and callbacks into hooks and lowers the App hook-call ceiling.
  • devswha/ovis#1754: Adds the App hook-call ceiling test that this change updates.
Merge Risk: ⚪ Minimal · up to 20996

No actionable merge-blocking risk is established for this move-only refactor.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main refactor: moving connection-chip state into a hook.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description explains the refactor, resulting behavior, implementation details, affected files, and validation results. It includes typecheck, ceiling test, browser and integration results, and fas…
Full details: Description check

Explanation

The description explains the refactor, resulting behavior, implementation details, affected files, and validation results. It includes typecheck, ceiling test, browser and integration results, and fast checks. The Change and Validation content is present under equivalent headings. The integration failure is clearly identified as reproducible on unchanged origin/main and unrelated to this PR.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

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 three states and paneLost were already contiguous in App, and no other hook sat between them.
  • All 37 effects keep identical bodies and order.
  • Both callbacks keep [] dependencies, with the stable setter passed in.
  • Counting App's hooks on the TypeScript AST confirms 176 → 171.

The ceiling test and the typecheck pass. The PR's browser lane ran green locally (bun run check integration browser).

All required checks are green and no review thread is open.

@devswha
devswha merged commit e44fc9f into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-connection-chip-hook branch October 23, 2026 13:22
devswha added a commit that referenced this pull request Oct 23, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant