Repository navigation
refactor(app): move the alerts and notification state into a hook - #1768
Conversation
Move the alert prefs, notification and push state, the droplet and chime callbacks, the sound effects, the push registration and the Alerts item's bell into src/lib/useAlerts.ts, called where the notifications state stood. The event stream calls onRoster/onPaneStatus/onPaneExited at the exact points the lines stood, with takeNotificationTargetRef passed at event time. The four callbacks (dropIn, chime, onRoster/onPaneStatus/onPaneExited) are useCallback([]) so the stream does not resubscribe. App's now-unused alerting copy and imports are dropped; the hook ceiling is lowered to 144. Plan .omo/plans/app-stores-split.md wave 5.
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
🔇 Additional comments: 3
src/lib/useAlerts.ts: 1
1-221: LGTM!src/app-hooks.test.ts: 1
5-5: LGTM!src/App.tsx: 1
636-636: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Update the SSE effect dependencies to match the new callbacks.
The effect body now calls
onRoster,onPaneStatusandonPaneExited, but the dependency array does not list them. The array still listsdropInandchime, which the body no longer references.This is not a runtime bug today. All three callbacks are
useCallback(..., [])inuseAlerts, so their identity never changes and the stream does not resubscribe. The mismatch has two costs:
react-hooks/exhaustive-depscannot treat values returned from a custom hook as stable. It will report the missing entries.- If a later edit adds a dependency to one of these callbacks, the stream keeps the old callback and its stale closure.
Replace the stale entries with the callbacks the effect uses. After that,
dropInandchimemay no longer need to be destructured inApp.♻️ Proposed change
- }, [locked, scheduleRefetch, dropIn, chime, reorderCoordinator]); + }, [locked, scheduleRefetch, onRoster, onPaneStatus, onPaneExited, reorderCoordinator]);Source: Learnings
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: devswha/ovis
- Branch: refactor/app-alerts-hook
- File: .coderabbit.yaml
- Commit: fee0c61
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2b59a877-3018-4277-b27c-6e7660e297c0
📒 Files selected for processing: 3
src/App.tsxsrc/app-hooks.test.tssrc/lib/useAlerts.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.
|
Hold this PR for one more push, please. I found it does not follow the plan's rule R1 exactly. The rule: every contiguous moved block becomes its own hook call, at that block's original line, so effect order stays identical. What this PR does instead: it calls one The coming push: it keeps
With that, every effect and listener keeps its exact registration order. I'll update the body with it. |
|
Merge pass: this PR isn't purely moved code. Three pieces of the event-stream handler become hook callbacks, so this comment records the review. Gate review, by a reviewer on a different model than the author's:
Stale closures, checked by the merge pass:
Tests at this head: 76 unit tests (app-hooks, droplet, notifications, alertTurns, alertSound, conventions) and the typecheck pass. All required checks are green and no review thread is open. |
A follow-up to PR #1768, wave 5 of the App.tsx split. The plan is `.omo/plans/app-stores-split.md` in the maintainer's workspace. The plan's rule R1 says every contiguous block moved out of `src/App.tsx` becomes its own hook call, placed at that block's original line, so effect and listener order stay exactly as they were. PR #1768 broke that rule: - **What it did:** it gathered six separate blocks into one `useAlerts` call at the `notifications` line. - **What changed as a result:** three effects ran earlier in a commit than before: - the alert-sound player effect; - the sound-unlock effect; - the push re-registration effect, which also moved ahead of the event-stream effect. - **Harm found:** none. PR #1768's body and the merge pass's review found no behaviour change from this. This PR restores the exact order anyway, so no such argument is needed. ## What changes `src/lib/useAlerts.ts` now exports one hook per block. Each is called in `App.tsx` at its block's original line (the line numbers are from before PR #1768): | Block | Hook | Called where the block stood | |---|---|---| | alert prefs (`alerts`, `alertsRef`, `alertsOn`, `alertsOnRef`) | `useAlertPrefs({ settings })` | right after `useSettings()` | | `notifications`, `pushOn`, `pushOnRef` | `useNotificationState()` | after the connection chip | | status and turn refs, in-app and sound switches | `useAlertRefs({ settings })` | after `lockedRef`, before `followFocusRef` | | `dropIn`, the sound player effect, `chime`, the sound-unlock effect, plus the three event-stream callbacks | `useAlertSignals({ … })` | before the event-stream effect | | `enableNotifications`, `disableNotifications`, the push re-registration effect | `useNotificationSwitch({ … })` | after the event-stream effect and `handleServerMessage` | | the bell, `bellVisible`, `alertsOffDot` (no hooks) | plain `alertsBell({ … })` | where the bell was computed | - **Moved lines:** none changes. Each hook's body is its block's lines from PR #1768. - **Effects and callbacks:** every effect is back at its original line. The three event-stream callbacks (`onRoster`, `onPaneStatus`, `onPaneExited`) are `useCallback([])` hooks without effects, so where they sit inside `useAlertSignals` changes no order. - **Hook ceiling:** unchanged at 144, because the same hook calls left App. ## Checks - **`--color-moved`:** `git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD` shows only: - the single call replaced by six calls; - the import line; - `useAlerts` split into hook signatures, params interfaces, doc comments and returns. The block bodies show as moved, or as unchanged in place. - **Moved blocks are exact:** all six blocks match `App.tsx` before PR #1768 (`53b85127e`) byte for byte, at lines 225-232, 496-500, 509-518, 604-647, 744-787 and 1317-1343. - **Positions:** the line before each new call is the line that came before its block on `53b85127e`. - **Typecheck:** `bun run typecheck` passes. - **Unit tests:** **129 pass, 0 fail across 9 files**, from: `HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/notifications.test.ts src/lib/droplet.test.ts src/lib/alertTurns.test.ts src/lib/alertSound.test.ts src/lib/push.test.ts src/lib/notificationTarget.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, 68.4s) - **Alert browser scripts:** each run with `bun run check run --build bun scripts/<name>.ts`: `alert-sound-regression`, `droplet-regression`, `droplet-demo-regression`, `notification-startup-regression`, `notification-view-regression` and `push-settings-regression` each exit 0. No changelog fragment: users see no change.
…ks (#1770) 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.
Wave 5 of the App.tsx split. The plan is
.omo/plans/app-stores-split.mdin the maintainer's workspace, and plan-reviewer approved it. It follows PR #1766.This wave moves this device's alert and notification state out of
src/App.tsxintosrc/lib/useAlerts.ts. It also moves what the event stream does for alerts when a pane's status changes or a pane exits.This is not purely moved code. The event-stream effect stays in App, and three pieces of its handler become calls to hook callbacks, so this PR waits for a review. Every line the pieces held moves byte for byte, apart from indentation.
What moves
Six blocks move verbatim, in source order, into
useAlerts:alerts,alertsRef,alertsOnandalertsOnRef.notifications,pushOnandpushOnRef.statusRef,turnStartRef,lastTurnRef,alertInAppRefandalertSoundRef.followFocusRefstays in App.dropIn, the alert-sound player effect,chime, and the sound-unlock effect.enableNotifications,disableNotifications, and the push re-registration effect.bellVisibleandalertsOffDot.In the event-stream effect, three pieces become calls at exactly the points the lines stood:
onRoster(payload.machines)is the roster'sseedStatusesline. The only token that changes ispayload.machines, which becomes the parametermachines.onPaneStatus(machine, message, takeNotificationTargetRef)covers the status bookkeeping, the in-app drop and chime, and the system notification. ThesetMachines(applyPaneStatus…)update stays in App, right after the call.onPaneExited(machine, message, takeNotificationTargetRef)covers the ended-turn drop and chime, then the ended notification. Theherdr-usage-changeddispatch stays in App, before the call.takeNotificationTargetRefis declared later in App, so the effect passes the ref object at event time. The moved lines still readtakeNotificationTargetRef.currentat the same moment as before.Why behaviour is unchanged
Hook call position: the hook is called where
notificationswas declared, before App'sfollowFocusRef. The alert values were not read anywhere between their old declaration and that point. Everything the hook takes is declared before it:settings,updateSettings,t,locked,selectionRef,drawerOpenRef,splitRef,splitShownRefandmachinesRef.No resubscription:
dropIn,chime,onRoster,onPaneStatusandonPaneExitedare alluseCallback(..., []). The event-stream effect's dependency list[locked, scheduleRefetch, dropIn, chime, reorderCoordinator]is unchanged, so the stream does not resubscribe.enableNotificationsanddisableNotificationskeep[updateSettings].Effect order: three effects now run earlier in a commit than before:
lockedis stillnull.The bell: it is computed during render. It reads only values the hook owns, plus
settingsandt.Hook ceiling:
APP_HOOK_CEILINGdrops from 163 to 144. That is the 19 hook calls that moved: 3 in A, 3 in B, 5 in C, 5 in D and 3 in E.Checks
--color-moved:git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEADshows 361 lines as moved. The other 57 lines are:onRosterline;Moved lines are exact: blocks A-F appear byte for byte in the hook (lines 225-232, 496-500, 509-518, 604-647, 744-787 and 1317-1343 of
App.tsxon53b85127e). The event-stream lines 677-689, 704-709 and 711-714 appear apart from indentation.Typecheck:
bun run typecheckpasses.Unit tests: 129 pass, 0 fail across 9 files, from:
HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/notifications.test.ts src/lib/droplet.test.ts src/lib/alertTurns.test.ts src/lib/alertSound.test.ts src/lib/push.test.ts src/lib/notificationTarget.test.ts src/lib/i18n.test.tsCeiling test: adding
const zz = useState(false);to App.tsx makessrc/app-hooks.test.tsfail.bun run check fast: passes after the rebase (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.5s)bun run check integration browser: the browser lane exits 0 (every browser script passed, 1816 s), including the alert scripts: the Alerts item off/on, blocked-permission switch, Settings push test, notification startup, a tapped pane alert opening chat/terminal/workspace, in-app alerts (open pane spared, drop-in, flick, close, timeout, off stays off, split half spared) and the alert sound (no sound before a tap, Settings toggle with preview, two tabs chime once). It ran on this commit before its rebase onto the latest main, which changed only PaneTerminal files. The integration lane's only failure isserver/api.contract.test.ts"creates, edits, searches, inspects, and closes an owned workspace" (line 1540), which fails the same way on unchangedorigin/mainon 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 there, and in eight other files, so it needs a rebase either way.No changelog fragment: users see no change.