Skip to content

fix(settings): guard ClaudeSubscriptionCard setState calls with mountedRef - #204

Merged
jackwener merged 1 commit into
mainfrom
yuejing/fe-bug-hunt-1
Jun 24, 2026
Merged

fix(settings): guard ClaudeSubscriptionCard setState calls with mountedRef#204
jackwener merged 1 commit into
mainfrom
yuejing/fe-bug-hunt-1

Conversation

@jackwener

Copy link
Copy Markdown
Member

Stacked behind #202 but touches a different file (ProvidersPanel.tsx vs SettingsModal.tsx / OnboardingHero.tsx / main.tsx). No merge conflict either way.

What

The Claude subscription card launches a browser OAuth flow that takes seconds-to-minutes. Closing the Settings modal while a `startLogin` / `submitPaste` / `cancelLogin` / `logout` / `refreshQuota` call is in flight produced `setState on unmounted component` warnings — loud in dev, masks real bugs in prod. `refreshExperimentalGate` and `refresh` had the same exposure.

How

Mirrored the `mountedRef` pattern already in use by other settings sub-cards in this file:

  • `claudeCardMountedRef = useRef(true)` with an unmount-flip effect
  • Every `await` is followed by an `if (!claudeCardMountedRef.current) return;` before any setState / toast call
  • Finally blocks gate `finishPendingAction()` the same way so the pending-action ref doesn't leak past unmount

No behavior change when the card stays mounted (the common case).

Verification

Local disk still sitting at 100% (system-level — not the repo), so I could not run `pnpm install && pnpm test` end-to-end before pushing. Diff is small and surgical:
```
1 file changed, 34 insertions(+), 5 deletions(-)
```
Please review the diff + run the test suite before merging. I'll rerun the gate once disk space frees up.

…edRef

PR-FE-BUG-HUNT-1 (MEDIUM from kenji-led bug-hunt 2026-06-24 round 1):
the Claude subscription card launches a browser OAuth flow that takes
seconds-to-minutes. Closing the Settings modal while a `startLogin`,
`submitPaste`, `cancelLogin`, `logout`, or `refreshQuota` call is in
flight produced `setState on unmounted component` warnings (loud in
dev, masks real bugs in prod). `refreshExperimentalGate` and `refresh`
had the same exposure.

Mirrored the `mountedRef` pattern already in use by other settings
sub-cards in this file:
- `claudeCardMountedRef = useRef(true)` with a unmount-flip effect
- Every `await` is followed by an `if (!claudeCardMountedRef.current) return;`
  before any setState / toast call
- Finally blocks gate `finishPendingAction()` the same way (so the
  pending-action ref doesn't leak past unmount)

No behavior change when the card stays mounted (the common case).

Scoped to a single file to minimize merge conflict surface with the
in-flight PR #202 (which doesn't touch ProvidersPanel.tsx).
jackwener added a commit that referenced this pull request Jun 24, 2026
PR-FE-BUG-HUNT-4 (LOW from kenji-led bug-hunt 2026-06-24 round 1):
`refreshMessagesUntilTurn` polls `readMessages` every 40ms for up to
1200ms while waiting for a freshly-sent user turn to land in the
session journal. The setState was already gated on
`activeIdRef.current === sessionId`, but the IPC call itself kept
firing until the deadline — burning bandwidth and CPU on a session
the user no longer cared about.

Fix: check `activeIdRef.current !== sessionId` at the top of each
loop iteration AND immediately after the await. Bail early so the
polling cycle stops, not just the setState. Same guard on the
deadline-fallthrough `refreshMessages(sessionId)`.

Behavior change is invisible when the user stays on the same session
(common case). Saves up to 30 IPC roundtrips per session-switch
during the post-send window when the user navigates fast.

Single function, single file. No conflict with #202 / #204 / #206 /
#207 since none of those touch `refreshMessagesUntilTurn`.
@jackwener
jackwener merged commit 6e498ed into main Jun 24, 2026
@jackwener
jackwener deleted the yuejing/fe-bug-hunt-1 branch June 24, 2026 17:31
jackwener added a commit that referenced this pull request Jun 24, 2026
#206)

PR-FE-BUG-HUNT-2 (MEDIUM from kenji-led bug-hunt 2026-06-24 round 1):
`WechatQrLoginModal`'s 3-second polling effect listed the whole
`result` object in its dep array. Every successful QR refresh
produces a new `result` reference → effect cleanup tears down the
interval → effect re-armed → 3-second clock restarts from zero.

In practice the polling cadence drifted: each refresh pushes the
next poll up to ~5.9 s after the previous poll instead of the
intended 3 s. Over a long scan, this delays the moment the modal
notices `loggedIn: true` from the bridge.

Fix: derive a boolean `shouldPollQr = !!result?.ok && !result.loggedIn
&& !result.expired` and depend on `[shouldPollQr]`. The interval is
armed once when scanning starts and torn down once when the gating
state flips (logged in, expired, or error). `reloadQrCode` only
touches stable refs (`loadingQrRef.current`) and state setters, so
the captured closure is safe across renders.

Scoped to a single function (`WechatQrLoginModal` at lines 687-693)
to keep merge surface minimal with the in-flight PRs #202 / #204.
jackwener added a commit that referenced this pull request Jun 24, 2026
Kenji aesthetic audit reminder 4/6 (msg `6cc0e04d` 2026-06-24,
finding #2): Tooltip is a high-frequency hover/focus surface and
should use instant positioning + compositor-only popup transitions.
Two sites violated:

1. Positioner: `transition-[top,left,right,bottom,transform]`
   — `top` / `left` / `right` / `bottom` are layout-trigger
   properties. Every reposition (e.g. anchor moved by scroll, or
   side flipped on collision) ran through layout + paint instead
   of GPU compositor. Reduced to `transition-transform` so the
   transform-based reposition still tweens smoothly; the layout
   positioning happens instantly off-frame.

2. Popup: `transition-[width,height,scale,opacity]` — `width` /
   `height` are layout-trigger. Reduced to `transition-[scale,opacity]`,
   which is what the data-starting-style / data-ending-style scale-98
   + opacity-0 actually animate. The popup-width / popup-height
   CSS vars still set the size; just no longer transitioned.

Net behavior: tooltip pops in/out via scale+fade (compositor),
repositions via transform (compositor). Layout properties are
applied instantly per frame instead of crossfading.

Drawer's `transition-[transform,box-shadow,height,background-color]`
and Tabs' `transition-[width,translate]` indicator are flagged in
kenji's audit but deferred — both interact with swipe gesture / tab
sizing logic and need a focused PR with visual smoke verification.

Scoped to 2 lines in 1 file to keep merge surface minimal with the
in-flight PRs #202 / #204 / #206.
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