feat(mathjax): upgrade mathjax from v2 to v4#270
Conversation
|
Thanks for the pull request, @navinkarkera! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Migrate MathJax v2 Hub.Queue/Hub.getAllJax/Callback APIs to v3/v4 startup.promise/typesetPromise/typesetClear in Problem display.js, formula_equation_preview.js, and HtmlBlock init. - Problem.display.js: replace Hub.Queue(Typeset) with startup.promise.then(typesetPromise), Hub.getAllJax with startup.document.getMathItemsWithin, jax.root.toMathML with startup.toMML - Formula equation preview: replace Hub.signal.Interest/Queue/getAllJax with startup.promise.then(typesetClear; textContent; typesetPromise) - HtmlBlock: call typesetPromise on student_view load - Bump version to 0.17.1
Update display_spec.js and formula_equation_preview_spec.js MathJax mocks from v2 (Hub.Queue, Hub.getAllJax, Startup.signal.Interest, Callback.After, jax.root.toMathML) to v3/v4 (startup.promise synchronous mock, typesetClear, typesetPromise, startup.toMML, startup.document.getMathItemsWithin).
60e1f68 to
56660c7
Compare
Summary
Upgrade MathJax from v2.7.5 → v4.1.2 across all XBlocks (problem, discussion, html). The v2
MathJax.Hub.Queue(...)/.Hub.Config()/.Hub.getAllJax()API is removed upstream. This PR ports all JS interactions to v4'sMathJax.typesetPromise()/MathJax.typesetClear()/MathJax.startup.promiseAPI.Co-authored by: GPT 5.5(xhigh)
Manual testing
Before merging, verify each xblock type in a devstack with the corresponding edx-platform MathJax v4 branch:
1. Problem XBlock — formula preview (AsciiMath / calculator syntax)
<formulaequationinput>(e.g., the built-in "Formula Problem" template).R_1*R_2/R_3into the input field.<img.loading>remains visible while a request is in flight and is not destroyed by the preview update.sin(x)andsqrt(y^2+1).2. Problem XBlock — formula preview (explicit TeX syntax)
\(E=mc^2\).$$\sum_{i=1}^{\infty} \frac{1}{n^2}$$.3. Discussion — math rendering in posts
$x^2 + y^2 = z^2$(inline) and$$\int_0^\infty e^{-x}\,dx$$(display).MathJax.Hub.Browser.4. HTML XBlock — math in content
\[ \sum_{i=1}^n i = \frac{n(n+1)}{2} \].MathJax.startup.promise.then(() => typesetPromise([element]))on initialization — no console errors.5. Graceful degradation — CDN failure
cdn.jsdelivr.net.startup.promise.then(...)chains (.catch()is present informula_equation_preview.js;utils.jsandhtml.pyskip typesetting when MathJax is absent).Risks
input/asciimathloaded. Its ownmathjax_include.jsis a guarded fallback (if (typeof MathJax === 'undefined')). If the host changes config without enabling AsciiMath input, formula preview (backtick-delimited syntax) breaks silently.noerrorspackage: Loaded in config; silently swallows MathJax rendering errors. Same behavior as v2, intentional.messageStyle: "none"not ported — v4 may show brief "Loading MathJax..." overlay. Cosmetic only.Merge checklist:
Check off if complete or not applicable: