Skip to content

refactor(app): move the dialogs', files' and palette's state into hooks - #1770

Merged
devswha merged 1 commit into
mainfrom
refactor/app-dialog-hooks
Oct 23, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/app-dialog-hooks

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Wave 6 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 #1768 and PR #1769.

This wave moves the state behind the dialogs, the file panels, the command palette and the pane-coverage check out of src/App.tsx. That is seven blocks, into five new files.

Following the plan's rule R1:

  • Each contiguous block becomes one hook, called at that block's own line.
  • The new-session area has three separate blocks, so its file exports three hooks.

Effect and listener registration order stay identical. That includes the popstate listeners that useFileViewer and useRepoDiffViewer register, and the coverage MutationObserver.

What moves

File Hook Block (App.tsx on 41189ee36) Contents
src/lib/useMachineDialog.ts useMachineDialog() 246-255 machineDialog, addPcFocusReturn, closeMachineDialog
src/lib/useNewSessionDialog.ts useNewSessionMachine() 256 newSessionMachineId
src/lib/useCommandPalette.ts useCommandPalette() 395-397 paletteOpen, paletteQuery, openPalette
src/lib/useFilePanels.ts useFilePanels({ settings, filePanelAvailable, selectedPaneId, selectedMachineId }) 405-463 filesOpen; the useFileViewer, useRepoDiffViewer and useFocusReturn calls; presentation, fileDocked and both docked-close effects; webPage and openWebPage; collapsing and its effect; presentFile, reportFileKind, toggleFilePresentation, viewFile
src/lib/useNewSessionDialog.ts useNewSessionState({ initialLink }) 465-475 newSessionOpen, newPrefill, newFields, pendingCreate, newTab, sessionHistory
src/lib/usePaneCoverage.ts usePaneCoverage({ contentKey }) 866-879 dialogCover, contentReady, the MutationObserver effect
src/lib/useNewSessionDialog.ts useSessionHistoryList({ … }) 1352-1367 closeNewSession, closeSessionHistory, useRecentResumes, the away-PC probe effect, sessionHistoryWorkspace and its effect
  • What stays in App, as the plan says:
    • the pendingCreate effect, whose deps include actions;
    • contentKey;
    • paneInFront;
    • every call site.
  • Dependency lists and returned refs: every useCallback/useMemo dependency list is unchanged. openWebPage and viewFile are context values, and keep their exact deps. Refs (addPcFocusReturn, pendingCreate, collapsing) are returned as the same objects.
  • Imports: App drops the imports only the moved code used.
  • Hook ceiling: APP_HOOK_CEILING drops from 144 to 113, after moving 31 builtin hook calls.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD shows 228 lines as moved. The other 99 lines are:
    • App's narrowed imports, the five new imports and the seven calls;
    • the ceiling;
    • the new files' imports, params types, signatures and returns.
  • Moved blocks are exact: all seven blocks appear byte for byte in their hooks.
  • Positions: the line before and after each call is the line that surrounded its block on 41189ee36.
  • Typecheck: bun run typecheck passes.
  • Unit tests: HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/i18n.test.ts src/lib/filePresentation.test.ts src/lib/webPanel.test.ts src/lib/paletteSeed.test.ts: 42 pass, 0 fail.
  • Ceiling test: adding const zz = useState(false); to App.tsx makes src/app-hooks.test.ts fail.
  • 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, 1815 s), including the file viewer, repo diff, files prompt, palette, machine dialog, session history, new-session, recent folders, deep link and sidebar activity 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.

Move-only: moved blocks plus imports, hook signatures and returns, seven calls and the lowered ceiling. No changelog fragment: users see no change.

The machine dialog, new session, session history, file panels, command palette and pane
coverage blocks move into five files under src/lib, seven hooks in all, each called in
App at its block's own line so effect and listener order stay the same. The pendingCreate
effect, paneInFront and contentKey stay in App. APP_HOOK_CEILING is lowered to 113.
Plan .omo/plans/app-stores-split.md wave 6.
@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 41189ee and 1653ee4.

📒 Files selected for processing: 7
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/useCommandPalette.ts
  • src/lib/useFilePanels.ts
  • src/lib/useMachineDialog.ts
  • src/lib/useNewSessionDialog.ts
  • src/lib/usePaneCoverage.ts

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

📝 Summary

Summary by CodeRabbit

  • Refactor
    • Reorganized how the app manages dialogs, sessions, command palette, file panels, and pane visibility. Existing interactions remain available, with no new user-facing features noted.

App.tsx now delegates dialog, session, command-palette, file-panel, and pane-coverage state to dedicated hooks. The extracted hooks manage the corresponding state and actions.

Changes: App hook extraction

Layer / File(s) Summary
Dialog, palette, and session state
src/lib/useMachineDialog.ts, src/lib/useNewSessionDialog.ts, src/lib/useCommandPalette.ts, src/App.tsx, src/app-hooks.test.ts
Dedicated hooks manage machine-dialog focus return, command-palette state, new-session state, and session-history selection. App.tsx uses the hooks for these states and actions. The hook-call ceiling test limit changes from 144 to 113.
File and web panel coordination
src/lib/useFilePanels.ts, src/App.tsx
useFilePanels coordinates file and diff viewers, docked panels, and web pages. It validates panel links, handles file-presentation changes, and exposes file-opening and presentation controls.
Pane coverage tracking
src/lib/usePaneCoverage.ts, src/App.tsx
usePaneCoverage tracks dialog coverage and pane-content presentation with a mutation observer. App.tsx uses the hook for the current content key.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 1653e

The hook extraction has no identified issue that needs correction before merge; proceed with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 7 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 "refactor(app): move the dialogs', files' and palette's state into hooks" matches the main change. The PR moves seven state blocks out of src/App.tsx into hooks under src/lib for the machine…
Description check Passed The description follows the template's intent. It has a Change section that explains the problem and the resulting behavior, and it describes the refactor: seven blocks moved into five files, rule R1,…
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.
Full details: Title check

Explanation

The title "refactor(app): move the dialogs', files' and palette's state into hooks" matches the main change. The PR moves seven state blocks out of src/App.tsx into hooks under src/lib for the machine dialog, new-session state, command palette, file panels, and pane coverage. The title is specific and uses a conventional commit prefix, and it does not cover every detail, which is acceptable. It omits the session-history and pane-coverage parts, but those are secondary to the main change.

Full details: Description check

Explanation

The description follows the template's intent. It has a Change section that explains the problem and the resulting behavior, and it describes the refactor: seven blocks moved into five files, rule R1, ordering and deps kept identical, and the ceiling lowered. It has a Validation section that lists typecheck, unit tests, the ceiling test, fast checks, and the browser integration lane, with one known failure explained. The description does not link an issue, and the template's changelog note is addressed by the 'No changelog fragment' statement. The template asks for a changelog check, which the description does not mention, but the core sections are present and the check is mostly complete.

✨ 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 6 of the App.tsx split). It is merged on its checks, without waiting for a CodeRabbit review, as AGENTS.md allows.

Line-level diff check. Comparing removed and added lines as multisets, the only differences are imports, the seven calls, the ceiling, and the new files' wrapper and interface lines.

Gate review (on a different model than the author's):

  • Substituting all seven hook bodies back in place of their calls rebuilds App's component body from 41189ee byte for byte.
  • These are preserved:
    • hook, effect and listener order, including the popstate listeners and the coverage MutationObserver;
    • captures;
    • returned ref identities;
    • the deps of the openWebPage and viewFile context values.
  • App now makes 113 builtin hook calls, counted on the TypeScript AST.

Tests at this head:

  • 37 unit tests pass (merge-pass run).
  • Both typechecks pass.
  • file-viewer-regression passes from a fresh build, covering mobile and desktop history, palette layering and double-click diff collapse.

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

@devswha
devswha merged commit 705dcb8 into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-dialog-hooks branch October 23, 2026 17:24
devswha added a commit that referenced this pull request Oct 23, 2026
Wave 7 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 #1770.

This wave moves the access state out of `src/App.tsx` into
`src/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`, `canSignOut` and `pairedFromAddress`,
with their comments.
- `pairCode`'s initializer still runs `takePairCode()` at the same point
in App's render.
- It also returns `readBridgeHealth`: the bridge-health read that opened
`loadHealth`, now a `useCallback(..., [])`. Its body is the original two
lines (the `fetchBridgeHealth()` try and its catch), and it uses only
stable setters.
- **`useLockedRef({ locked })`**, where `lockedRef` stood. It returns
the same ref object, with the render-time assignment.

**Not purely moved code:** in `loadHealth`, the two bridge-health lines
become `await readBridgeHealth();`. `loadHealth`'s dependency list stays
`[]`. `readBridgeHealth` is stable, so the closure `loadHealth` holds
from the first render runs the same code as before. `loadHealth`'s
identity, which the polling effect and `unlock`/`lock` depend on, is
unchanged.

**Stays in App, as the plan says:**
- the pairing effect;
- `unlock`;
- the hashchange effect;
- `lock`.

**Hook ceiling:** `APP_HOOK_CEILING` drops from 113 to 107, after moving
four `useState` and two `useRef` calls.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 30
lines as moved. The other 26 lines are:
  - App's narrowed imports and the new import;
  - the two calls and the `await readBridgeHealth();` line;
- the new file's imports, signatures, the `readBridgeHealth` wrapper
lines and the returns;
  - the ceiling.
- **Moved lines are exact:** the moved blocks match `App.tsx` on
`705dcb8ff` byte for byte, at lines 257-267, 403-404 and 413-414.
- **Positions:** the line before and after each call is the line that
surrounded its block.
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** `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.
- **Ceiling test:** adding `const zz = useState(false);` to App.tsx
makes `src/app-hooks.test.ts` fail.
- `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 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.
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