Skip to content

Commit

Permalink
Merge pull request #1044 from mathjax/issue3167a
Browse files Browse the repository at this point in the history
Fix menu to not rerender if no typesetting has occurred.  (mathjax/MathJax#3167)
  • Loading branch information
dpvc authored Feb 1, 2024
2 parents 3894352 + 3867c1c commit c48f82c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 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
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 c48f82c

Please sign in to comment.