Skip to content

fix: ScoreConversion leaks a valtio subscription per render - #610

Open
zjncs wants to merge 1 commit into
oss-compass:mainfrom
zjncs:fix/score-conversion-subscription
Open

zjncs wants to merge 1 commit into
oss-compass:mainfrom
zjncs:fix/score-conversion-subscription

Conversation

@zjncs

@zjncs zjncs commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Problem

subscribeKey is called in the render body and its returned unsubscribe is discarded: every re-render of every mounted ScoreConversion (used on nearly all analyze chart cards - TableList, TotalScore, LineChart, ...) adds another permanent subscription with a stale onePoint/onChange closure. One navbar toggle of the score system (ChartDisplaySetting writes chartUserSettingState.onePointSys) then fans out to N accumulated callbacks (N = total renders so far), which keep firing after unmount.

Fix

Move the subscription into useEffect with cleanup (deps [onePoint, onChange]).

Verification

  • New ScoreConversion.test.tsx, RED proof: render 4x with stable props, flip chartUserSettingState.onePointSys - onChange fires 4 times before the fix (valtio notifies via microtask, the test flushes with act), exactly once after.
  • The no-op case (store value equal to current) is pinned too.
  • Suite run: all analyze tests pass (one pre-existing unrelated failure on main).

Risk

None identified - subscription semantics unchanged for the single-mount case.

subscribeKey is called in the render body and its returned unsubscribe is
discarded: every re-render of every mounted ScoreConversion (used on
nearly all analyze chart cards) adds another permanent subscription with a
stale onePoint/onChange closure. One navbar toggle of the score system
then fans out to N accumulated callbacks (N = renders so far), which keep
firing after unmount.

Move the subscription into useEffect with cleanup. Red proof in the test:
rendering 4 times and flipping chartUserSettingState.onePointSys fires
onChange 4 times before the fix, exactly once after.
Copilot AI balanced review requested due to automatic review settings October 21, 2026 05:15
@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@zjncs is attempting to deploy a commit to the codersett's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
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.

2 participants