fix: Don't cache wrapped text before MathJax finishes loading.

This commit is contained in:
Daniel J. Geiger 2023-03-13 13:01:52 -05:00
parent b988f67759
commit b17ed4dc29

View File

@ -248,12 +248,12 @@ const loadMathJax = async () => {
errorSvg = mathJax.adaptor.outerHTML(mathJax.mmlSvg.convert(errorMML)); errorSvg = mathJax.adaptor.outerHTML(mathJax.mmlSvg.convert(errorMML));
errorAria = useSRE ? mathJax.mmlSre.toSpeech(errorMML) : "ERR"; errorAria = useSRE ? mathJax.mmlSre.toSpeech(errorMML) : "ERR";
// Finalize loading MathJax
mathJaxLoaded = true;
// Clear any caches from before loading MathJax // Clear any caches from before loading MathJax
clearCaches(); clearCaches();
// Finalize loading MathJax
mathJaxLoaded = true;
if (mathJaxLoadedCallback !== undefined) { if (mathJaxLoadedCallback !== undefined) {
mathJaxLoadedCallback(isMathElement); mathJaxLoadedCallback(isMathElement);
} }
@ -1201,7 +1201,7 @@ const wrapMathElement = function (element, containerWidth, next) {
const spaceWidth = getTextWidth(" ", font); const spaceWidth = getTextWidth(" ", font);
for (let index = 0; index < lines.length; index++) { for (let index = 0; index < lines.length; index++) {
const mathLineKey = `${containerWidth} ${fontSize} ${mathProps.useTex} ${mathProps.mathOnly} ${lines[index]}`; const mathLineKey = `${containerWidth} ${fontSize} ${mathProps.useTex} ${mathProps.mathOnly} ${lines[index]}`;
if (wrappedMathCache[mathLineKey] !== undefined) { if (isMathJaxLoaded && wrappedMathCache[mathLineKey] !== undefined) {
wrappedLines.push(...wrappedMathCache[mathLineKey].split("\n")); wrappedLines.push(...wrappedMathCache[mathLineKey].split("\n"));
continue; continue;
} }
@ -1299,7 +1299,11 @@ const wrapMathElement = function (element, containerWidth, next) {
} }
} }
} }
wrappedMathCache[mathLineKey] = wrappedLines.slice(currLineNum).join("\n"); if (isMathJaxLoaded) {
wrappedMathCache[mathLineKey] = wrappedLines
.slice(currLineNum)
.join("\n");
}
} }
if (wrappedLines[0] === "") { if (wrappedLines[0] === "") {