Skip to content

Reduce ChatMarkdown settings rerenders - #3536

Merged
juliusmarminge merged 1 commit into
mainfrom
cursor/component-performance-optimization-f123
Jun 23, 2026
Merged

Reduce ChatMarkdown settings rerenders#3536
juliusmarminge merged 1 commit into
mainfrom
cursor/component-performance-optimization-f123

Conversation

@cursor

@cursor cursor Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Changed ChatMarkdown table/code-block local wrap state to read the initial word-wrap preference from the client settings snapshot instead of subscribing every markdown table and code block to future client settings updates.
  • Keeps the table/code block wrap toggles locally owned while avoiding unrelated rerenders when global word-wrap settings change.

Why

React Doctor flagged ChatMarkdown for rerender-lazy-state-init: useState(useClientSettings(...)) subscribed each markdown table/code block and reran settings selection on every render even though the result was only used as initial local state. This caused markdown tables and code blocks to rerender when the global word-wrap setting changed, despite their local wrap state not changing.

React Scan evidence captured with React Scan enabled:

  • Before: before_chat_markdown_react_scan_rerenders.mp4 — toggling word wrap flashes MarkdownTable and MarkdownCodeBlock render boxes.
  • After: after_chat_markdown_react_scan_no_rerenders.mp4 — the same toggles flash only the toggle control; markdown tables/code blocks no longer rerender.

UI Changes

No user-facing visual change intended. This is an interaction/render-performance fix validated with before/after React Scan recordings.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes
Open in Web View Automation 

Note

Reduce rerenders in ChatMarkdown by replacing hook-based state initializers

In ChatMarkdown.tsx, MarkdownTable and MarkdownCodeBlock previously called useClientSettings as a state initializer, which subscribed each component to settings store updates on every render. They now use a plain readInitialWordWrapSetting getter (wrapping getClientSettings()) as a lazy initializer, so the settings store is only read once at mount time.

Macroscope summarized 0b1e390.


Note

Low Risk
Render-performance only; local wrap toggles are unchanged and there is no auth, data, or API surface change.

Overview
Stops every markdown table and code block from subscribing to client settings when they only need the global word-wrap value once at mount.

MarkdownTable and MarkdownCodeBlock no longer call useClientSettings inside useState. They use a lazy initializer readInitialWordWrapSetting() backed by getClientSettings(), so wrap/expand toggles stay local and global word-wrap changes no longer rerender those blocks. Intended behavior is unchanged aside from fewer renders.

Reviewed by Cursor Bugbot for commit 0b1e390. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jun 23, 2026
@juliusmarminge
juliusmarminge marked this pull request as ready for review June 23, 2026 18:24
@macroscopeapp

macroscopeapp Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Small performance optimization that replaces reactive hook subscriptions with one-time reads for initializing word wrap state. The change is self-contained with no new features or significant behavioral impact.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge
juliusmarminge merged commit c6c6491 into main Jun 23, 2026
20 checks passed
@juliusmarminge
juliusmarminge deleted the cursor/component-performance-optimization-f123 branch June 23, 2026 18:47
simonbetton pushed a commit to simonbetton/reviewer that referenced this pull request Jun 29, 2026
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
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.

2 participants