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:
@@ -167,6 +167,12 @@ export const highlightLinesInWorker = async (code: string, lang: string): Promis
|
||||
return result?.type === 'highlightLines' ? result.lines : null;
|
||||
};
|
||||
|
||||
/** Return an already-tokenized line result without scheduling a worker request. */
|
||||
export const getCachedHighlightedLines = (code: string, lang: string): string[] | null => {
|
||||
const cached = resultCache.get(cacheKeyFor('highlightLines', lang, code));
|
||||
return cached?.type === 'highlightLines' ? cached.lines : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tokenize `code` with the given resolved TextMate theme and return per-line
|
||||
* styled runs with offsets — for building CodeMirror decorations that match the
|
||||
|
||||
Reference in New Issue
Block a user