Skip to content

refactor(app): move the Settings dialog navigation state into a hook - #1754

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

devswha merged 1 commit into
mainfrom
refactor/app-settings-dialog-hook

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Wave 1 of the App.tsx split. The plan is .omo/plans/app-stores-split.md in the maintainer's workspace. It was approved by plan-reviewer, and 형 confirmed the hook approach.

This wave moves the Settings dialog navigation state out of src/App.tsx into a hook that App calls in the same place. App still owns the state, because the hook runs inside App's own render. So the same updates happen in the same commits, and hook, effect and listener order are unchanged.

What changes

  • Moved, verbatim (only the indentation changes), into the new src/lib/useSettingsDialog.ts:

    • App.tsx lines 515-537 (settingsOpen, settingsLinkPage, settingsLinkSection, settingsPage, settingsSection);
    • closeSettings, settingsLinkPageRef and onSettingsPage;
    • the two Settings history effects (onSettingsHistory, recordSettings).

    Every initializer and dependency list is unchanged.

  • Stays in App.tsx: one line at line 516, const { settingsOpen, … } = useSettingsDialog(initialLink);. It replaces the block at the same position: after the viewFile callback and before newSessionOpen. App no longer uses onSettingsHistory or recordSettings, so those two names leave its import.

  • New src/app-hooks.test.ts: a ceiling on the number of hook calls in App.tsx, set to 179, its count after this move.

    • It counts useState, useRef, useReducer, useEffect, useLayoutEffect, useMemo, useCallback and useSyncExternalStore calls, including calls with type arguments.
    • Type arguments are matched bracket by bracket, so a function-typed ref like useRef<() => Promise<void>> counts too.
    • Every later wave lowers the ceiling to its new count, so App's state cannot grow back unnoticed.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD shows 46 lines as moved. The other lines are:
    • the two App imports;
    • the one destructuring call;
    • in the hook file: its imports, doc comment, signature and return object;
    • the new test file.
  • Typecheck: bun run typecheck passes.
  • Unit tests: HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/lib/settingsHistory.test.ts src/lib/sheetHistory.test.ts src/lib/deepLink.test.ts gives 56 pass, 0 fail.
  • Mutation check: adding useState(false), useRef<number>(0) or useRef<() => void>(() => {}) to App.tsx each makes src/app-hooks.test.ts fail (180 > 179).
  • Browser regressions: each run with bun run check run --build bun scripts/<name>.ts, and each exited 0.
    • settings-pages-demo
    • deep-link-demo (settings=, section=, Back and Forward)
    • render-crash-demo
    • cliproxy-settings
    • preferences-sync
    • lan-exposure-notice
    • telemetry
  • bun run check fast: passes (unit 6245 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.4s)

Outside PRs that touch the same files

No other maintainer PR touches these files. One outside contributor's PR touches src/App.tsx: #1427.

  • git merge-tree shows it already conflicts with main in src/App.tsx.
  • It conflicts the same way with this branch, so it needs a rebase either way.

Move-only: moved lines plus the hook's signature and imports, one call and the new ceiling test. No changelog fragment: users see no change.

The Settings dialog state, its two history effects and its callbacks move
verbatim into src/lib/useSettingsDialog.ts. App calls the hook where they
stood, so hook and effect order are unchanged. src/app-hooks.test.ts caps
App.tsx's hook calls at the new count (179).
Plan .omo/plans/app-stores-split.md wave 1.
@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 d7c3f82 and 2d0134a.

📒 Files selected for processing: 3
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/useSettingsDialog.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
    • Settings dialog navigation continues to support linked pages and sections, and opening or closing the dialog is reflected in navigation history.
  • Tests
    • Added a check to help keep the app’s hook usage within an established limit.

App now gets Settings dialog navigation and history behavior from useSettingsDialog. A test sets a maximum count of recognized hook calls in App.tsx.

Changes: Settings dialog state and integration

Layer / File(s) Summary
Extract and integrate Settings dialog state
src/lib/useSettingsDialog.ts, src/App.tsx, src/app-hooks.test.ts
useSettingsDialog initializes navigation from initialLink, handles page changes and closing, and responds to Settings history. App uses the hook. A test checks that App.tsx has no more than 179 recognized hook calls.

Priority: ⬇️ Low

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to 2d013

The Settings dialog extraction appears to preserve its behavior and is ready to merge after 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 33.33% 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 "refactor(app): move the Settings dialog navigation state into a hook" matches the main change. The PR moves Settings dialog navigation state, callbacks, and two history effects from src/App…
Description check Passed The description covers the change, the validation steps, and the scope. It explains the move, the one-line call site in App.tsx, the new hook-call ceiling test, the typecheck and unit test results, th…
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 Settings dialog navigation state into a hook" matches the main change. The PR moves Settings dialog navigation state, callbacks, and two history effects from src/App.tsx into src/lib/useSettingsDialog.ts. The title is concise and specific, and it follows a conventional commit style.

Full details: Description check

Explanation

The description covers the change, the validation steps, and the scope. It explains the move, the one-line call site in App.tsx, the new hook-call ceiling test, the typecheck and unit test results, the browser regression runs, and the open PR #1427 conflict. It does not follow the template exactly: the '## Change' section describes the problem and behavior only loosely, and the '## Validation' section lists checks but does not explicitly cover contract-test coverage, which the template asks for on HTTP/WS changes. The description also has no changelog note, and it explains that no changelog fragment is needed. Those points are acceptable for a move-only refactor. The description includes a non-English term ('형') and an internal plan path reference that a reviewer outside the maintainer's workspace cannot open.

✨ 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 review (head 2d0134a): a gate reviewer on a different model than the author's checked this.

The extraction preserves behaviour.

  • The moved code is verbatim: same initializers, dependency arrays and effect bodies.
  • Hook and effect order inside App is unchanged.
  • What the moved effects capture is still correct.
  • The returned callbacks keep stable identities.

Checks run: 56 focused tests, 45 convention tests, typecheck, and the deep-link-demo browser regression. All passed.

A nit on the guard, not blocking: src/app-hooks.test.ts counts hooks with a regex over the source text, so it can miscount in both directions. The reviewer reproduced both against copies of App.tsx held in memory:

  • A comment such as // useState(false) is counted: 180 is reported while App still makes 179 real calls, so the test fails on a comment.
  • A real call with a comment before its parentheses, useState /* initial */ (false), is missed. 180 real calls report as 179, and the test passes.

The second case is contrived, and the guard does its job for ordinary code. The repo already ships the TypeScript API, so counting the call expressions on a TypeScript AST would make it exact. That's worth folding into a later wave, which lowers this ceiling anyway.

Approved. It merges once its checks are green.

@devswha
devswha merged commit 595a333 into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-settings-dialog-hook branch October 23, 2026 12:01
devswha added a commit that referenced this pull request Oct 23, 2026
Wave 2 of the App.tsx split. The plan is
`.omo/plans/app-stores-split.md` in the maintainer's workspace. It
follows #1754.

This wave moves the layout notice out of `src/App.tsx` into
`src/lib/useLayoutNotice.ts`. That is the line shown over the pane when
a PC's bridge refuses a palette layout call. Both hooks run inside App's
render, so updates and effect order are unchanged.

## What changes

- **Moved verbatim into two hooks:**
- `useLayoutNotice()` holds the `layoutNotice` state and its 6-second
timer effect, with their comment. It returns `{ layoutNotice,
setLayoutNotice }`.
- `useLayoutRefused(setLayoutNotice, t)` holds the `layoutRefused`
callback with its comment and its `[t]` dependency list.
- **Stays in `App.tsx`:** each block becomes one call at its own former
position, so effect order is unchanged.
- The first sits between the `error` state and the authentication state.
  - The second sits just before the notification-target block.
- **Imports:** `routeMissing` leaves App's `./lib/api.ts` import,
because only the moved callback used it.
- **Hook ceiling:** `APP_HOOK_CEILING` in `src/app-hooks.test.ts` drops
from 179 to 176. That is App's new count, after moving one `useState`,
one `useEffect` and one `useCallback`.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 28
lines as moved. The other lines are:
  - the `./lib/api.ts` import line, without `routeMissing`;
  - 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 regressions:** each run with `bun run check run --build bun
scripts/<name>.ts`, and each exited 0.
  - `ui-contexts-regression.ts` (it runs the update-notice check)
  - revision-bound-update-demo
  - telemetry
  - lan-exposure-notice
  - machine-conflict
- `bun run check fast`: passes (unit 6245 pass, 0 fail, 13 skip in 443
files, 8 at a time, 57.7s)

## 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.
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