Repository navigation
fix: render math through a MathJax v2 and v4 compatible helper - #2454
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2454 +/- ##
=======================================
Coverage 95.53% 95.53%
=======================================
Files 198 198
Lines 22820 22820
Branches 1543 1543
=======================================
Hits 21801 21801
Misses 765 765
Partials 254 254
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
feanil
marked this pull request as ready for review
September 22, 2026 15:59
feanil
force-pushed
the
feanil/mathjax-v4-compat
branch
from
October 1, 2026 18:54
ce9044c to
5f9f32c
Compare
openedx/openedx-platform#33555 upgrades the platform from MathJax 2.7.5 to 4.1.2. v4 removed the queue-based `MathJax.Hub` API in favour of `MathJax.typesetPromise`, so the two `MathJax.Hub.Queue` calls in ORA throw once that lands and math stops rendering in prompts and in submitted responses. The stub in oa_shared.js did not cover this. It only installed a no-op `Hub` when `window.MathJax` was undefined, and under v4 the global is defined, it just has no `Hub`. Route both call sites through a `typesetMath` helper that prefers the v4 API, falls back to the v2 one, and does nothing when the runtime provides no MathJax at all. That last case is what the stub was for, so the stub goes away. Supporting both versions means this does not have to be sequenced against the platform upgrade. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feanil
force-pushed
the
feanil/mathjax-v4-compat
branch
from
October 26, 2026 16:51
5f9f32c to
2054658
Compare
The response step before submission had no `allow--latex` class, unlike the submitted, graded, self, peer, training, grade and leaderboard steps, so `Server.renderLatex` skipped it. The prompt's math only rendered when the platform's one-time MathJax startup typeset happened to run after ORA inserted the step. Under MathJax 4 (openedx/openedx-platform#33555) that race loses most of the time: prompt math rendered on 2 of 8 page loads in a local test, and on 8 of 8 with this class added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MathJax 3 and 4 only define `MathJax.typesetPromise` once startup has finished, so requiring it up front skipped the v3/v4 branch whenever ORA rendered before startup was done. MathJax 4's AsciiMath input also defines a legacy `MathJax.Hub`, so in that window the call fell through to the v2 branch and queued into a Hub that does nothing. Wait on `MathJax.startup.promise` instead. The same race left the textline preview blank in the problem block on the MathJax 4 test stack for openedx/openedx-platform#33555. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@navinkarkera can you look at this when you have a sec, we need to land this before we can land the mathjax fixes in openedx-core and openedx-platform. |
navinkarkera
approved these changes
Oct 27, 2026
navinkarkera
left a comment
There was a problem hiding this comment.
@feanil Nice, clean and simple.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR - ORA's two MathJax calls use the v2
MathJax.HubAPI, which MathJax v4 removed. openedx/edx-platform#33555 upgrades the platform to 4.1.2, and when it lands those calls throw and math stops rendering in ORA prompts and submitted responses. This routes them through a helper that works on both v2 and v4, so it can merge now rather than being sequenced against the platform upgrade.What changed?
oa_mathjax.jsexportingtypesetMath(element). It prefers v4'sMathJax.typesetPromise, falls back to v2'sMathJax.Hub.Queue, and does nothing when the runtime provides no MathJax.oa_server.js::renderLatexandlms/oa_base.js::bindLatexPreviewnow call it instead ofMathJax.Hub.Queuedirectly.oa_shared.js. It guarded ontypeof window.MathJax === 'undefined', which is false under v4, so it never engaged where it was needed. The helper covers the no-MathJax case it existed for.Testing Instructions
make test-jspasses: 289 of 290 with 1 skipped. There is a pre-existing flake in the "unsubmitted assessments" specs that also fails onmaster(it moves betweenoa_self.jsandoa_staff_area.jswith Jasmine's random spec order). Notemake test-jsrather thannpm test, since the fixtures come from therender-templatesstep.The bug itself reproduces without the branch: with the global set to
{}, which is what v4 presents, the oldMathJax.Hub.Queue(['Typeset', MathJax.Hub, el])raisesTypeError: Cannot read properties of undefined (reading 'Queue'). Thedoes not throw when MathJax is v4-shaped but not readyspec covers that state against the new helper.To check it by hand, open an ORA with latex enabled and confirm math renders in the prompt, in the response preview, and in a submitted response, on a platform serving either MathJax version.