mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +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 ||
|
||||
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;
|
||||
return getDecorations({ doc: transaction.doc, name, lineNumbers });
|
||||
}
|
||||
@@ -247,11 +257,12 @@ export function CodeHighlighting({
|
||||
}
|
||||
|
||||
void Promise.all([...languagesToImport].map(loadLanguage)).then(
|
||||
(language) => {
|
||||
if (language && languagesToImport.size && !view.isDestroyed) {
|
||||
(results) => {
|
||||
const loaded = results.filter((lang): lang is string => !!lang);
|
||||
if (loaded.length && !view.isDestroyed) {
|
||||
view.dispatch(
|
||||
view.state.tr.setMeta("codeHighlighting", {
|
||||
langLoaded: language,
|
||||
langLoaded: loaded,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user