Skip to content

fix: make rapid response work with MathJax v4 - #969

Merged
arslanashraf7 merged 4 commits into
mainfrom
arslan/rapid-response-mathjax-v4
Nov 13, 2026
Merged

arslanashraf7 merged 4 commits into
mainfrom
arslan/rapid-response-mathjax-v4

Conversation

@arslanashraf7

@arslanashraf7 arslanashraf7 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

N/A. Upstream context: openedx/openedx-platform#33555 (MathJax v4 upgrade)

Description (What does it do?)

On edx-platform master the rapid response panel shows no graph and "Open problem now" spins forever. Master now loads MathJax 4.1.2, whose asciimath input leaves a MathJax.Hub object on the page with a Queue() that throws, and rapid.js called it on every chart render.

  • Use the MathJax v2 Hub API only when MathJax.version starts with 2..
  • On newer versions, typeset tooltips with typesetPromise() and skip typesetting the chart's x axis labels.
  • Skip the window-resize re-render until the first responses fetch has loaded.
  • Bump rapid-response-xblock to 0.12.1.
Implementation details
  • The browser error was TypeError: Cannot read properties of undefined (reading 'Push') at Object.Queue in mathjax@4.1.2/input/asciimath.js, called from renderMathHJax. On page load it fired after the controls were drawn, so the button showed without a graph. On click it fired before the toggle_block_open_status request was sent, so the "Opening problem" spinner never cleared.
  • The version is checked instead of the presence of MathJax.Hub, because Hub exists on v4 too.
  • The tooltip call passed $tooltipContainer.el, which is undefined on a jQuery object. It now passes the DOM node, so v2 typesets the tooltip instead of the whole page.
  • On v4 the x axis labels keep their raw TeX text. The v2 code moved MathJax's SVG output into the chart, and the v4 build the platform loads produces HTML, which cannot go inside the chart's SVG.
  • Answer text written with $...$ also stays raw on v4: the Hub.Config call that added $ as a delimiter is v2-only, and the platform's v4 config only declares \(...\) and [mathjaxinline].
  • A resize before the first fetch threw Cannot read properties of undefined (reading 'None') from the run dropdown, because the state had no total_counts yet.

How can this be tested?

Tested in a local Tutor dev environment on an edx-platform branch 10 commits ahead of upstream master, which loads mathjax@4.1.2:

  • Install this branch's rapid_response_xblock in LMS and CMS.
  • As staff, open a unit with a multiple choice problem enabled for rapid response.
  • Before this change: no graph, and "Open problem now" spins forever with no toggle_block_open_status request in the LMS log.
  • With this change: the panel loads, "Open problem now" opens the problem, and closing it works. The LMS log shows toggle_block_open_status returning 200.
  • Answers containing math, on MathJax 4.1.2 (the test course has none, so the responses JSON was rewritten in the page to Option (a) \(x^2\), $y_1$ and Option (a) plain): the tooltip renders \(x^2\) and clears on mouseout with no math left in MathJax's document after repeated hovers, the \(x^2\) label splits onto two lines, the plain label doesn't, and a page-wide typeset leaves the chart's labels as raw TeX.

Not tested:

  • A platform that loads MathJax v2 (ulmo, verawood). The v2 calls are unchanged apart from the tooltip node.
  • Answers containing math on MathJax v2.
  • There are no JS tests for rapid.js, and the integration tests do not run it.

Screenshots

Rapid response panel as staff on edx-platform master (MathJax 4.1.2).

Before (main) After (this PR)
Before: Live Response panel is empty, no chart and no Open problem now button After: chart renders with a hover tooltip and the Open problem now button

Additional Context

🤖 Generated with Claude Code

edx-platform master loads MathJax 4.1.2. Its asciimath input leaves a
MathJax.Hub object on the page whose Queue() throws, and rapid.js called
it on every chart render, so the chart never drew and "Open problem now"
never sent its request.

- Use the MathJax v2 Hub API only when MathJax.version starts with "2.".
- On newer versions typeset tooltips with typesetPromise() and leave the
  x axis labels as raw TeX.
- Pass the tooltip DOM node to MathJax instead of the undefined
  jQuery ".el" property.
- Skip the resize re-render until the first responses fetch has loaded.
- Bump rapid-response-xblock to 0.12.1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:13

@agent-optibot agent-optibot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Supports rapid response panels with MathJax v4 while preserving MathJax v2 support.

  • Fixes: MathJax v4 rendering failures by using typesetPromise() and restricting Hub calls to v2.
  • Fixes: premature chart rendering during window resize before the first responses fetch completes.
  • Changes: the package version to 0.12.1 for the rapid response XBlock.

Dependencies changed: src/rapid_response_xblock/pyproject.toml

Details for reviewers

Risks

  • Answer text using $...$ remains unrendered on MathJax v4 because $ delimiters are configured only for v2.

Core files: src/rapid_response_xblock/rapid_response_xblock/static/js/src_js/rapid.js

More changes

  • Changes: MathJax v4 chart x-axis labels to remain as raw TeX because HTML cannot render inside the chart SVG. (rapid.js)

Unchanged

  • MathJax v2 continues using its Hub API for chart and tooltip typesetting.

Summary of effe9cf · React 👍 or 👎 on my comments to tune what I raise · Commands · Review config

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tooltip handlers replace or clear typeset content without calling typesetClear(), causing MathJax to retain orphaned expressions and detached DOM across repeated hovers.

1 open issue
What changed in this PR

Updates the rapid response XBlock for MathJax v4, addressing chart-rendering errors that prevent the panel from loading and problems from opening.

Changes:

  • Restricts legacy MathJax calls to v2 and uses typesetPromise() for newer-version tooltips, leaving chart-axis math unrendered.
  • Prevents resize-triggered rendering before response data loads.
  • Bumps rapid-response-xblock to 0.12.1 and updates the lockfile.
File Description
uv.lock Synchronizes the plugin version to 0.12.1.
src/​rapid_response_xblock/​rapid_response_xblock/​static/​js/​src_js/​rapid.js Adds version-aware MathJax handling, corrects the tooltip DOM reference, and guards early resize rendering.
src/​rapid_response_xblock/​pyproject.toml Bumps the plugin release version to 0.12.1.

Review effort: Balanced

@agent-optibot agent-optibot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status: Code Looks Good 👍

No blocking issues found.

📌 Reviewed up to the latest commit · ⏱️ Review completed in 5 minutes

  • 🔄 re-review this PR

Address review feedback on #969: call typesetClear() before the shared
tooltip's content is replaced so MathJax doesn't retain orphaned
expressions, serialize that with pending typesets, and stop passing the
bare MathJax global into the IIFE so the file loads when MathJax isn't
defined yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark chart SVGs tex2jax_ignore on MathJax v3+ so the platform's page-wide
typeset doesn't blank the raw TeX tick labels, match a literal \( / \)
instead of any parenthesis when detecting math, read window.MathJax once
in setTooltipContent, and trim the mathJaxHub comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Underscore's _.includes on a string compares single characters, so
_.includes(text, "\\(") never matched and \(...\) answers stopped
typesetting on MathJax v4 and splitting in chart labels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@asadali145 asadali145 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fixes! Re-tested on local Tutor (edx-platform master, MathJax 4.1.2): \(x^2\) tooltips typeset and clear again, axis labels stay raw TeX after resize and on a cold load, and open/close works with no console errors. The MathJax v2 path is untested on my side.

@arslanashraf7
arslanashraf7 merged commit 0578c24 into main Nov 13, 2026
13 checks passed
@arslanashraf7
arslanashraf7 deleted the arslan/rapid-response-mathjax-v4 branch November 13, 2026 06:45
blarghmatey added a commit to mitodl/lehrer that referenced this pull request Nov 30, 2026
)

* chore(deps): hold verawood-only pins that Renovate keeps proposing

Renovate opened bumps for three overrides in build_manifest.yaml that
are held on purpose, with nothing in its config to say so:

- rapid-response-xblock on the verawood mitx cells stays on 0.12.0,
  because Verawood loads MathJax 2 and 0.12.1 onward is built for
  MathJax 4 (#426, mitodl/open-edx-plugins#969). #414 proposed 0.12.2.
- openedx-forum on the verawood cells exists only to reach the 0.4.7
  Typesense fix. 0.5.0 gates the forum HTTP API behind
  FORUM_ENABLE_HTTP_API and 0.6.0 adds a migration that no edx-platform
  branch pins yet (master is on 0.5.0). #371 proposed 0.6.1.
- edx-django-utils 8.2.0 onward requires Python 3.12, and the ulmo xpro
  cell runs 3.11. Verawood moves to 8.2.1 separately, which leaves ulmo
  as the only 8.1.0 match. Ulmo retires when xPRO moves to Verawood in
  production on 2026-12-16; the rule goes with it.

The rapid-response and edx-django-utils rules match on the current
version because the same package is pinned in cells that should keep
updating.

Claude-Session: https://claude.ai/code/session_01FGZebFCSK2StX76C2fxunU

* fix: scope the openedx-forum hold to 0.4.x pins and correct the edx-django-utils note

Without matchCurrentVersion, the openedx-forum rule would also cap a cell
that already pins 0.5 or later below 0.5. The edx-django-utils
description claimed the verawood cells are not matched, which only holds
once #457 bumps them to 8.2.1.

Claude-Session: https://claude.ai/code/session_01FGZebFCSK2StX76C2fxunU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants