Skip to content

Prevent unrelated client settings rerenders#4052

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/component-performance-optimization-2f3c
Draft

Prevent unrelated client settings rerenders#4052
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/component-performance-optimization-2f3c

Conversation

@cursor

@cursor cursor Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Apply client-settings selectors inside useSyncExternalStoreWithSelector instead of subscribing components to the full settings snapshot first.
  • Use shallow equality for selected values so primitive and object selectors remain stable across unrelated preference updates.
  • Keep full-snapshot consumers on Object.is semantics.

Why

Selector consumers such as the diff panel and sidebar previously re-rendered whenever any client preference changed. React Scan confirmed that a component selecting only wordWrap rendered on every unrelated sidebarThreadPreviewCount update.

UI Changes

React Scan before/after recordings are attached to the Cursor run:

  • Before — react_scan_settings_subscription_before.mp4: five unrelated updates move the selected consumer from 2 to 12 render calls; changing wordWrap moves it to 14.
  • After — react_scan_settings_subscription_after.mp4: five unrelated updates leave the consumer at 4; changing wordWrap correctly moves it to 6.

The fixture used React Strict Mode, so each actual consumer commit appears as two render calls. React Scan is visibly enabled in both recordings.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after recordings for the interaction change
  • I included a video for animation/interaction changes

Validation: vp check --fix, vp run typecheck, and the web settings hook unit test all pass. A post-fix React Doctor performance scan completed across 985 files with no finding in useSettings.ts.

Open in Web View Automation 

Note

Prevent unrelated rerenders in useClientSettings by subscribing to store slices

Rewrites useClientSettings to use useSyncExternalStoreWithSelector, so components only re-render when their selected slice of client settings changes. Uses shallow equality when a selector is provided, and Object.is otherwise. Adds use-sync-external-store as a runtime dependency.

Macroscope summarized 909cbf7.

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant