Skip to content

refactor(app): move the pane lens and split view state into hooks - #1773

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

devswha merged 1 commit into
mainfrom
refactor/app-lens-split-hooks

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

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.

Six hooks in two files (src/lib/usePaneLens.ts, src/lib/useSplitView.ts), each called at its block's own line.
The lens is still settled during App's render, inside usePaneLens; plain split functions stay plain.
storedView, storedSelection and storeSelection moved verbatim and App imports them back.
Ceiling lowered to 62; four type-only split! assertions replace the narrowing through splitOn.
Plan .omo/plans/app-stores-split.md wave 9.
@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 3a449c9 and bfc8fea.

📒 Files selected for processing: 4
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/usePaneLens.ts
  • src/lib/useSplitView.ts

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

📝 Summary

Summary by CodeRabbit

  • Refactor
    • Pane views and split layouts continue to preserve selections and respond to changes in available panes, connections, and screen size.
    • When a pane in a split layout is no longer available, the layout selects a replacement when possible or ends the split.

App now delegates pane-lens selection, view persistence, split state, layout reconciliation, and drag-and-drop handling to dedicated hooks. Slot rendering still derives the machine, pane, and side from split selection. The app-hook ceiling test limit is reduced from 90 to 62.

Changes: Pane lens and split-view behavior

Layer / File(s) Summary
Pane lens state and selection
src/lib/usePaneLens.ts, src/App.tsx
New hooks manage pane-lens defaults, persisted and page-scoped picks, notification overrides, and manual view changes. App delegates lens selection and view-pick handling to these hooks.
Split state, layout, and drag handling
src/lib/useSplitView.ts, src/App.tsx, src/app-hooks.test.ts
New hooks manage split persistence, roster reconciliation, split actions, docking, and drag previews. App delegates split behavior to the hooks and continues rendering the selected slots. The app-hook ceiling changes to 62.

Priority: ⬇️ Low

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to bfc8f

This refactor moves pane lens and split-view logic from App into dedicated hooks without any intended change in behavior. No concrete merge-blocking risk was found in the supplied evidence.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 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 change: moving pane lens and split view state from App.tsx into hooks.
Description check Passed The description explains the change, preserves hook ordering, identifies the affected files, and reports validation results, including the known baseline integration failure.
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.
✨ 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 9 of the App.tsx split). It merges on its checks without waiting for a CodeRabbit review, as AGENTS.md allows. The only non-move change is four type-only split! assertions.

Line check. Comparing removed and added lines, the only differences are:

  • imports;
  • the six calls;
  • the four split! lines;
  • the ceiling;
  • the new files' wrapper and interface lines.

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

  • Putting all six hook bodies back at their call sites, and dropping the four split! assertions, gives App's base body from 3a449c9 byte for byte.
  • These are unchanged:
    • hook, effect and listener order (lastKeyAt still registers after the sidebar's Escape listener);
    • the split validation, onDrop and drag-listener effects;
    • captures;
    • the convergence of the setState calls made during render.
  • Each split! is reached only when split is non-null.
  • Counting with the TypeScript AST, App now makes 62 hook calls.

Tests at this head:

  • 51 unit tests pass (split, paneLens, paneDrag, notificationTarget, app-hooks, conventions);
  • the typecheck passes;
  • the split-view browser suite passes on a fresh build.

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

@devswha
devswha merged commit 3f0cfce into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-lens-split-hooks branch October 23, 2026 20:02
devswha added a commit that referenced this pull request Oct 23, 2026
…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.
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