diff --git a/js_lib/knowl.js b/js_lib/knowl.js index e3974f0a2..fc6c8d91d 100644 --- a/js_lib/knowl.js +++ b/js_lib/knowl.js @@ -56,8 +56,11 @@ class SlideRevealer { this.animatedElement.setAttribute("open",""); this.triggerElement.setAttribute("open",""); this.contentElement.style.display = ''; - // Wait for the next frame to call the toggle function - window.requestAnimationFrame(() => this.toggle(true)); + // Trigger the animation to expand or collapse the knowl. + // Delay the MathJax typesetting until the knowl is visible to ensure proper measurements + // are taken, but before the unrolling begins. This helps avoid layout shifts and ensures + // smooth animation with correctly sized content. + MathJax.typesetPromise().then(() => window.requestAnimationFrame(() => this.toggle(true))); } else if (this.animationState === SlideRevealer.STATE.EXPANDING || this.animatedElement.hasAttribute("open")) { this.toggle(false); } @@ -312,7 +315,6 @@ class LinkKnowl { this.outputElement.append(...children); // render any knowls and mathjax in the knowl - MathJax.typesetPromise([this.outputElement]); addKnowls(this.outputElement); // force any scripts (e.g. sagecell) to execute by evaling them