mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Sporadic infinite loop rendering document with imported code blocks that have unknown languages (#12444)
This commit is contained in:
@@ -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,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user