fix: Sporadic infinite loop rendering document with imported code blocks that have unknown languages (#12444)

This commit is contained in:
Tom Moor
2026-05-24 12:03:02 -04:00
committed by GitHub
parent 9e725d618d
commit 1a4033dd2d
+14 -3
View File
@@ -221,6 +221,16 @@ export function CodeHighlighting({
langLoaded || langLoaded ||
isRemoteTransaction(transaction) isRemoteTransaction(transaction)
) { ) {
// Invalidate cached entries for blocks whose language just loaded
// so getDecorations rebuilds them with syntax highlighting applied.
if (Array.isArray(langLoaded)) {
for (const key of Object.keys(cache)) {
const pos = Number(key);
if (langLoaded.includes(cache[pos]?.node.attrs.language)) {
delete cache[pos];
}
}
}
highlighted = true; highlighted = true;
return getDecorations({ doc: transaction.doc, name, lineNumbers }); return getDecorations({ doc: transaction.doc, name, lineNumbers });
} }
@@ -247,11 +257,12 @@ export function CodeHighlighting({
} }
void Promise.all([...languagesToImport].map(loadLanguage)).then( void Promise.all([...languagesToImport].map(loadLanguage)).then(
(language) => { (results) => {
if (language && languagesToImport.size && !view.isDestroyed) { const loaded = results.filter((lang): lang is string => !!lang);
if (loaded.length && !view.isDestroyed) {
view.dispatch( view.dispatch(
view.state.tr.setMeta("codeHighlighting", { view.state.tr.setMeta("codeHighlighting", {
langLoaded: language, langLoaded: loaded,
}) })
); );
} }