Skip to content

Commit

Permalink
Fix menu to not rerender if no typesetting has occurred. (mathjax/Mat…
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Jan 27, 2024
1 parent 4cbd125 commit 86420a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
15 changes: 13 additions & 2 deletions ts/components/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface MathJaxObject extends MJObject {
elements: any[];
document: MATHDOCUMENT;
promise: Promise<void>;
rerenderPromise: Promise<void>;
/* tslint:disable:jsdoc-require */
registerConstructor(name: string, constructor: any): void;
useHandler(name: string, force?: boolean): void;
Expand Down Expand Up @@ -184,7 +185,7 @@ export namespace Startup {

/**
* The promise for the startup process (the initial typesetting).
* It is resolves or rejected in the ready() function.
* It is resolved or rejected in the ready() function.
*/
export let promise = new Promise<void>((resolve, reject) => {
promiseResolve = resolve;
Expand All @@ -206,6 +207,13 @@ export namespace Startup {
}
});

/**
* Non-null when MathJax.typeset() or MathJax.typesetPromise() have been performed
* (so the menu code can tell whether a rerender is needed when components are loaded)
* and then is equal to a promise after which rerendering can occur.
*/
export let rerenderPromise: Promise<void> = null;

/**
* @param {MmlNode} node The root of the tree to convert to serialized MathML
* @return {string} The serialized MathML from the tree
Expand Down Expand Up @@ -374,9 +382,12 @@ export namespace Startup {
document.options.elements = elements;
document.reset();
document.render();
if (!rerenderPromise) {
rerenderPromise = promise;
}
};
MathJax.typesetPromise = (elements: any[] = null) => {
promise = promise.then(() => typesetPromise(elements));
rerenderPromise = promise = promise.then(() => typesetPromise(elements));
return promise;
};
MathJax.typesetClear = (elements: any[] = null) => {
Expand Down
1 change: 0 additions & 1 deletion ts/input/tex/ams/AmsMappings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*************************************************************
*
* Copyright (c) 2017-2023 The MathJax Consortium
Expand Down
19 changes: 12 additions & 7 deletions ts/ui/menu/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,23 @@ export class Menu {

/**
* Rerender the output if we aren't in the middle of loading a new component
* (in which case, we will rerender in the callback performed after it is loaded)
* (in which case, we will rerender in the callback performed after it is loaded)
*
* @param {number=} start The state at which to start rerendering
*/
protected rerender(start: number = STATE.TYPESET) {
this.rerenderStart = Math.min(start, this.rerenderStart);
if (!Menu.loading) {
if (this.rerenderStart <= STATE.COMPILED) {
this.document.reset({inputJax: []});
}
this.document.rerender(this.rerenderStart);
this.rerenderStart = STATE.LAST;
const startup = MathJax.startup;
if (!Menu.loading && startup.rerenderPromise) {
startup.rerenderPromise = startup.promise = startup.rerenderPromise.then(
() => mathjax.handleRetriesFor(() => {
if (this.rerenderStart <= STATE.COMPILED) {
this.document.reset({inputJax: []});
}
this.document.rerender(this.rerenderStart);
this.rerenderStart = STATE.LAST;
})
);
}
}

Expand Down

0 comments on commit 86420a3

Please sign in to comment.