fix(web): keep the latest client setting visible while older saves drain #48307
main fromrefs/pull/48307/head·opened View on GitHubProblem#
When an asynchronous client-settings save is already in flight, toggling a client setting twice in quick succession can temporarily revert the rendered control and dependent views to the intermediate value while the older queued save runs. In WordWrapRow (apps/web/src/components/settings/TypographySettings.tsx:278), the controlled <Switch checked={settings.wordWrap} onCheckedChange={(checked) => updateSettings({ wordWrap: Boolean(checked) })} /> queues each toggle through useUpdateScopedSettings() → persistClientSettingsPatch (apps/web/src/hooks/useSettings.ts:790). In Electron, defaultClientSettingsPersistence awaits window.desktopBridge.setClientSettings(settings) (apps/web/src/localApi.ts:78 → apps/desktop/src/ipc/methods/clientSettings.ts:22), leaving clientSettingsPersistenceQueue pending across the async IPC round-trip. When the older queued callback runs in persistClientSettingsPatch, it reapplied its full patch whenever current[key] !== value without distinguishing another tab's refresh from a newer optimistic write, calling replaceClientSettingsSnapshot and emitting the stale boolean directly through useSyncExternalStoreWithSelector (useClientSettings → useScopedSettings) back to Switch's controlled checked prop with no debouncing or masking.
Deterministic repro on origin/main (43328e8f0a680a491c84995b398f5c635ff37a90):
- Start with hydrated client settings (
wordWrap: true) and gate the first twosetClientSettingspersistence calls (apps/web/src/hooks/useSettings.test.ts→keeps the latest setting visible while an older queued save runs). - Run
persistClientSettingsPatch({ snapShotFlash: false }), wait for the first save to start, then callpersistClientSettingsPatch({ wordWrap: false })andpersistClientSettingsPatch({ wordWrap: true }). - Release the first save so the older
wordWrap: falsequeued callback starts and blocks on itssetClientSettingscall. - Observed on
origin/main:getClientSettings().wordWrapreverted tofalse(emittingtrue → false → true → false) while the older save was held in flight. - Expected:
getClientSettings().wordWrapstaystrue(emitting onlytrue → false → true), and the final persisted snapshot has{ snapShotFlash: false, wordWrap: true }.
Change#
Track a monotonically increasing patch revision per ClientSettings key in apps/web/src/hooks/useSettings.ts. When a queued persistClientSettingsPatch callback runs, it only reapplies keys whose latest revision still matches that patch, omitting superseded keys while still reapplying unsuperseded keys after a cross-tab refresh and preserving pre-hydration deferral. This covers the shared web/desktop renderer client settings store (apps/web/src/hooks/useSettings.ts); mobile uses separate native settings state and no contracts, server, or i18n changes apply.
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- Base failure (
43328e8f0a680a491c84995b398f5c635ff37a90):vp test run apps/web/src/hooks/useSettings.test.ts -t "keeps the latest setting visible while an older queued save runs"failed atexpect(getClientSettings().wordWrap).toBe(true)withReceived: false. - Head pass (
b664d0160c156d8477501b7d3555638baaef7eb5):vp test run apps/web/src/hooks/useSettings.test.tspassed (14 passed), including the regression test for rapid toggles during an in-flight save and a multi-key cross-tab refresh preservation test. vp run check:changed: exit0onb664d0160c156d8477501b7d3555638baaef7eb5(format0.8s, lint1.7s, knip26.9s, typecheck 2 packages21.8s, tests 2 files / 21 tests22.9s, react compiler3.2s).- Before/after +
check:changedtranscript: https://gist.github.com/saphid/0836f3e4dff31e8ea0c02fca3db3eef8 - Not shown: Interactive Electron desktop UI capture or rendered-switch
scenarios:proverun with a manually gatedsetClientSettingsIPC response; the unit tests verify the external-store snapshot and subscriber emissions directly.
Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).
Not shown#
- apps/web/src/components/settings/TypographySettings.tsx:278 — The deterministic repro gates the store callback but does not drive the rendered switch. For scenarios:prove, specify the desktop IPC gate and assert the switch’s aria-checked stays true after releasing the first save while holding the older toggle save; capture a short before/after recording of that interval.
- apps/web/src/components/settings/useScopedSettings.ts:115 — Correct the draft’s call-path citation: the switch reaches persistClientSettingsPatch through the scoped writer here, not through the separate update hook at useSettings.ts:790.
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
b664d01Macroscope's review found this PR approvable — Per-setting revision tracking keeps newer client selections visible while older saves drain through the existing persistence queue. The change preserves defaults and storage interfaces, with no obvious material exposure beyond existing client-settings behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
Client settings patches now track revisions per key. Queued patches reapply only keys that have not been superseded. Tests cover queued updates, subscriber notifications, and cross-tab refreshes.
Changes: Client settings patches
Layer / File(s) Summary Track revisions and apply queued patches
apps/web/src/hooks/useSettings.ts,apps/web/src/hooks/useSettings.test.tsPersisted patches record revisions for their keys. Queued patches reapply only keys that remain current. Tests check subscriber updates, queued saves, and cross-tab refresh behavior. Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Merge Risk:
Minimal · up tob664d-
This change keeps the newest client setting visible while older saves are still in flight. No concrete merge-blocking risk remains after review.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: a fix that keeps the latest client setting visible while older queued saves finish. The changeset tracks per-key patch revisions in useSettings.ts so superseded keys a… Description check The description follows the template's main sections: Problem, Change, Scope, and Verification. It explains the bug, the revision-based fix, why no issue is needed for a small obvious bug, and gives c… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: a fix that keeps the latest client setting visible while older queued saves finish. The changeset tracks per-key patch revisions in useSettings.ts so superseded keys are not reapplied, which matches the title. The title is 72 characters and follows the conventional commit format the template suggests.
Full details: Description check
-
Explanation
The description follows the template's main sections: Problem, Change, Scope, and Verification. It explains the bug, the revision-based fix, why no issue is needed for a small obvious bug, and gives concrete test results with commit hashes. Gaps remain. The Scope section links no issue and cites no maintainer request, though it argues an issue is unnecessary. The Verification section lists rendered-switch and Electron UI evidence as not shown. The PR notes a before/after gist, but the reviewer notes ask for a rendered-switch proof and a short recording of the interval. The description also has a citation error the author should fix: the call path runs through useScopedSettings.ts:115, not useSettings.ts:790 as stated.
Resolution
Mostly complete. Before merge, consider these improvements: (1) Correct the call-path citation to apps/web/src/components/settings/useScopedSettings.ts:115 as the reviewer note states. (2) Add or link the rendered-switch verification: gate the desktop IPC response, assert the switch stays checked, and attach a short before/after recording of that interval, or state why it cannot be checked. (3) Confirm the Scope rationale for omitting an issue, or link one.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 43328e8
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4d5c30a9-f1b1-4383-8b96-d304035f97fd
Commits-
Reviewing files that changed from the base of the PR and between 43328e8f0a680a491c84995b398f5c635ff37a90 and b664d0160c156d8477501b7d3555638baaef7eb5.
Files selected for processing: 2-
apps/web/src/hooks/useSettings.test.tsapps/web/src/hooks/useSettings.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
-
-
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes