Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): keep the latest client setting visible while older saves drain #48307

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48307/headopened View on GitHub

Problem

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 two setClientSettings persistence 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 call persistClientSettingsPatch({ wordWrap: false }) and persistClientSettingsPatch({ wordWrap: true }).
  • Release the first save so the older wordWrap: false queued callback starts and blocks on its setClientSettings call.
  • Observed on origin/main: getClientSettings().wordWrap reverted to false (emitting true → false → true → false) while the older save was held in flight.
  • Expected: getClientSettings().wordWrap stays true (emitting only true → 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 at expect(getClientSettings().wordWrap).toBe(true) with Received: false.
  • Head pass (b664d0160c156d8477501b7d3555638baaef7eb5): vp test run apps/web/src/hooks/useSettings.test.ts passed (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: exit 0 on b664d0160c156d8477501b7d3555638baaef7eb5 (format 0.8s, lint 1.7s, knip 26.9s, typecheck 2 packages 21.8s, tests 2 files / 21 tests 22.9s, react compiler 3.2s).
  • Before/after + check:changed transcript: https://gist.github.com/saphid/0836f3e4dff31e8ea0c02fca3db3eef8
  • Not shown: Interactive Electron desktop UI capture or rendered-switch scenarios:prove run with a manually gated setClientSettings IPC 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

    2. Approvability

      Verdict: Approved at b664d01

      Macroscope'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).
    3. Explain Change →

      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.ts
      Persisted 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 to b664d

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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

      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.ts
      • apps/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.