Skip to content

refactor(app): move the selection and address bar state into hooks - #1774

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

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

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

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:

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.

Eleven hooks in two files: ten selection hooks in src/lib/useSelection.ts and
useAddressBar in src/lib/useAddressBar.ts, each called at its block's own line.
Listener and effect order unchanged; dependency lists byte-identical.
APP_HOOK_CEILING lowered to 24.
Plan .omo/plans/app-stores-split.md wave 10.
@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 3f0cfce and c254463.

📒 Files selected for processing: 4
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/useAddressBar.ts
  • src/lib/useSelection.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
    • Selection, shared-link navigation, and browser history handling have been reorganized while preserving existing behavior. You can continue opening linked sessions and files, using Back and Forward to revisit selections, and receiving a notice if a linked machine is no longer available. No user-facing features or workflows have been removed.

App delegates selection, link landing, machine-removal handling, and address-bar history to dedicated hooks. The hooks manage selection and navigation state, resolve link and notification targets, and handle linked-file opening and browser history. The App hook-call test ceiling is reduced from 62 to 24.

Changes: Selection and Navigation

Layer / File(s) Summary
Selection state and roster reconciliation
src/lib/useSelection.ts, src/App.tsx, src/app-hooks.test.ts
useSelection manages selection, link and notification targets, roster reconciliation, pane and layout state, and machine removal. App delegates these behaviors to the hook. The App hook-call ceiling changes from 62 to 24.
Address-bar history and linked files
src/lib/useAddressBar.ts, src/App.tsx
useAddressBar manages URL history, Back and Forward navigation, and opening pending linked files. App delegates address-bar synchronization to the hook.

Priority: ⬇️ Low

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to c2544

This is a behavior-preserving refactor that moves selection and address-bar logic into hooks. Review found no concrete regression, so it is ready to merge after the normal checks pass.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 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 identifies the main change: moving selection and address bar state from App.tsx into hooks.
Description check Passed The description includes the required Change and Validation sections. It explains the refactor, preserves behavior, lists moved hooks, and reports typecheck and test results, including the unrelated b…
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: Description check

Explanation

The description includes the required Change and Validation sections. It explains the refactor, preserves behavior, lists moved hooks, and reports typecheck and test results, including the unrelated baseline integration failure.

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

Pure move. Comparing removed and added lines as multisets, the only differences are imports, the eleven calls, the ceiling, and the new files' wrapper and interface lines.

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

  • Reinserting all eleven hook bodies reproduces App's base body from 3f0cfce byte for byte.
  • Preserved unchanged:
    • dependency lists;
    • effect, layout-effect and listener order (the pane popstate listener still registers before the New-workspace one);
    • commit-time selectionRef marking;
    • render-time ref assignments;
    • the takeNotificationTargetRef getter's identity;
    • the zoom redirect.
  • Not affected: no capture or TDZ regression, and no change to when herdr focus is called. Neither new file calls pane.focus.
  • App now makes 24 hook calls, counted on the TypeScript AST.

Tests at this head. 82 unit tests pass (deep link, selection mark, notification target, sheet and settings history, app-hooks, conventions). The typecheck passes, and the desktop and mobile deep-link browser regression passes on a fresh build.

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

@devswha
devswha merged commit deefbff into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-selection-hooks branch October 23, 2026 20:51
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