Fix markdown highlight render stability#2479
Merged
juliusmarminge merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Contributor
ApprovabilityVerdict: Approved Pure React render stability optimizations - extracting a component and hoisting inline JSX to constants. No runtime behavior changes, just standard performance patterns to prevent unnecessary re-renders. You can customize Macroscope's approvability policy. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
SuspenseShikiCodeBlockso cached-highlight renders no longer skip hooks.MessagesTimelineLegendList header/footer elements to avoid passing fresh element props on every render.Why
react-doctorflagged two hook-order errors inChatMarkdown.tsxcaused by returning cached highlighted HTML before callinguse()/useMemo()/useEffect(). This is both a correctness issue and a render hot path for assistant markdown/code blocks. The split keeps hook order stable while preserving the highlight cache. The timeline hoist removes avoidable prop churn in the virtualized message list.Scan evidence:
react-doctor: 75/100, 2 errors (ChatMarkdown.tsxhook-order violations).react-doctor: 76/100, 0 errors.totalEvents: 113,commits: 24,timelineRowFibers: 22.UI Changes
No intentional UI changes.
Checklist
Note
Fix markdown highlight render stability by extracting
UncachedShikiCodeBlockcomponentUncachedShikiCodeBlockcomponent, isolating theuse()call for the highlighter promise to prevent render instability.ListHeaderComponentandListFooterComponentin MessagesTimeline.tsx by replacing inline JSX with module-level constantsTIMELINE_LIST_HEADERandTIMELINE_LIST_FOOTER, avoiding unnecessary re-renders from new object references on each render.Macroscope summarized b3a7b9d.
Note
Low Risk
Low risk UI render-path refactor that preserves behavior while fixing React hook-order stability and reducing avoidable re-renders; main risk is subtle regressions in code highlighting/caching.
Overview
Fixes a React hook-order issue in markdown code highlighting by extracting the uncached Shiki path into
UncachedShikiCodeBlock, so cached-highlight renders no longer bypassuse()/useMemo()/useEffect().Reduces render churn in
MessagesTimelineby hoisting staticLegendListheader/footer elements into module-level constants instead of creating new JSX elements each render.Reviewed by Cursor Bugbot for commit b3a7b9d. Bugbot is set up for automated code reviews on this repo. Configure here.