fix: reduce code block highlight flicker
Preserve layout with invisible placeholders while worker highlighting loads Reuse cached highlighted lines on first render when available Differentiate loading from failed highlighting results for better fallback behavior
This commit is contained in:
@@ -54,7 +54,8 @@ export const VirtualizedCodeBlock: React.FC<VirtualizedCodeBlockProps> = React.m
|
||||
const syntaxVars = React.useMemo(() => getMarkdownSyntaxVars(currentTheme), [currentTheme]);
|
||||
// Tokenize the whole block in one worker call; rows index into the result.
|
||||
const fullText = React.useMemo(() => lines.map((line) => line.text).join('\n'), [lines]);
|
||||
const highlighted = useWorkerHighlightedLines(fullText, language);
|
||||
const highlightResult = useWorkerHighlightedLines(fullText, language);
|
||||
const highlighted = highlightResult.lines;
|
||||
|
||||
const shouldVirtualize = lines.length > VIRTUALIZE_THRESHOLD;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user