Skip to content

MathJax 2.7.3 is EOL with a split-brain CDN/local setup — upgrade to MathJax 3/4 with the WKWebView migration #509

Description

@schuyler

Current state (survey §4.3, §1.2)

  • MathJax 2.7.3 (EOL; 3.x since 2019, 4.x current). Split-brain delivery: the render path hard-codes the cdnjs CDN URL (kMPMathJaxCDN, MPRenderer.m:26), and the legacy WebResourceLoadDelegate swaps in the bundled local copy at runtime (MPDocument.m:1268-1281, workaround for MathJax hangs Chrome mathjax/MathJax#548).
  • The CSP must whitelist cdnjs.cloudflare.com and 'unsafe-eval' for MathJax 2.x (MPRenderer.m:508).
  • Typeset-completion is bridged via MPMathJaxListener + windowScriptObject (MathJax/init.js:10; MPDocument.m:1303, 1679) so native code can restore scroll position after typesetting.

Why this rides with (or immediately after) #111

The WKWebView migration breaks all three legs anyway: there is no per-resource willSendRequest hook (the CDN-swap dies), the windowScriptObject bridge becomes a WKScriptMessageHandler, and the DOM-replacement re-typeset script (MPDocument.m:1627-1683, MathJax.Hub.Queue) is 2.x-specific API. Since the completion-hook and delivery mechanisms must be rewritten regardless, rewriting them against a supported MathJax does the work once:

  • MathJax 3/4: MathJax.typesetPromise() replaces Hub.Queue — a cleaner fit for the async message-channel architecture (decision register D-6)
  • Fully local delivery via the Migrate from WebView to WKWebView #111 scheme handler kills the CDN dependency and lets the CSP drop 'unsafe-eval' and the CDN whitelist
  • Smaller bundle: 3/4 are modular; 2.x's local fallback + config machinery goes away

Note: milestone v3000.1.0 is deliberately WKWebView-only ("nothing else rides this train"), so this is either scoped as part of #111's JS-library verification phase or lands in the next train — maintainer's call. What should NOT happen is porting the 2.x CDN-swap + Hub.Queue machinery to WKWebView and then rewriting it again.

Migration checkpoints

  • Delimiter config: hoedown/cmark emit \(…\) / \[…\] — configure tex2jax/tex.inlineMath equivalently (2.x currently relies on CDN default config TeX-AMS-MML_HTMLorMML, MPRenderer.m:26-28)
  • htmlMathJaxInlineDollar preference behavior preserved
  • Typeset-completion → scroll-restore path re-verified (issue jumping of the editor persists when mathjax is enabled #325 regression class; MPMathJaxScrollTests.m)
  • MathJax golden fixtures (MPMathJaxRenderingTests.m) still pass — they assert on pre-typeset HTML, so should be unaffected; confirm

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency filerendering

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions