Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix menu to not rerender if no typesetting has occurred. (mathjax/MathJax#3167) #1044

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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