Self-host MathJax via @prosemark/latex vite plugin (url-import) - #150
Merged
Conversation
Replace deferred dynamic imports with a build-time side-effect import of mathjax/tex-svg.js (peer dependency of @prosemark/latex) so Vite fully bundles MathJax into webview.js before the webview loads. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
🦋 Changeset detectedLatest commit: 8e545e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@prosemark/core
@prosemark/latex
@prosemark/paste-rich-text
@prosemark/render-html
@prosemark/spellcheck-frontend
@prosemark/vscode-extension-integrator
commit: |
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
jsimonrichard
marked this pull request as ready for review
June 6, 2026 20:31
The tex-svg combined component loads sre/speech-worker.js at runtime, but Vite only emits webview.js. Turn off speech/enrichment for editor preview. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
The tex-svg bundle loads sre/speech-worker.js at runtime as a web worker. Vite inlines the main IIFE but cannot bundle workers loaded via importScripts, so copy mathjax/sre/ next to webview.js after each build. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Export copyMathJaxAssets from @prosemark/latex/vite-plugin-mathjax with a configurable copy list (default tex-svg.js + sre). The LaTeX VS Code webview loads MathJax via url-import from dist/webview/mathjax/ instead of bundling tex-svg into webview.js (~48 KB vs ~1.8 MB). Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
mathJaxPackageUrlFromWebviewScript used the last script tag, which was cspell-integration's webview.js when both companions are installed. Add scriptSrcIncludes and use latex-integration in the LaTeX webview. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Extend SubExtensionCallback with the webview instance so sub-extensions can resolve local resource URLs with webview.asWebviewUri instead of reverse-engineering script tags in the webview. The LaTeX integration now passes mathJaxPackageUrl into setup from the extension host, removing the scriptSrcIncludes workaround. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
VS Code integrations should pass mathJaxPackageUrl from the extension host via webview.asWebviewUri; script-tag discovery is no longer needed. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Sub-extension factories now receive { document, callProcAndForget,
callProcWithReturnValue, webview } so each integration can destructure
only what it needs without breaking when new fields are added.
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Explain that tex-svg loads sre/speech-worker.js separately, and that static-import setups must either disable a11y or copy and serve sre/. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Use a type guard for the webview vscode API instead of an unsafe cast, tighten the MathJax loader test helper, and include vite.config.mts in eslint file patterns. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
MathJax 4 removed skipStartupTypeset; use startup.typeset: false to skip automatic page typesetting. Update @prosemark/latex preconfiguration, docs, and tests accordingly. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
vite.config.mts is git-tracked source, but sibling VS Code extensions do not list their vite configs in eslint.config.ts and lint passes without it. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
The VS Code extension keeps speech support via url-import and copied sre/. Frame disabling a11y as a static-import tradeoff, not a preview default. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Describe the 0.0.2 bug as math failing when MathJax was bundled into the extension; drop the speech-worker cause (introduced in this PR). Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Self-host MathJax in the extension to resolve rendering issues.
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.
Summary
Self-host MathJax in the LaTeX VS Code extension via
url-importinstead of bundlingtex-svg.jsintowebview.js, and resolve the MathJax package URL from the extension host usingwebview.asWebviewUri.Changes
@prosemark/latex/vite-plugin-mathjax— Vite plugin to copy configurable paths from themathjaxnpm package (default:tex-svg.js+sre/) into the build output undermathjax/.@prosemark/vscode-extension-integrator—SubExtensionCallbackreceives context as a single object (includingwebview).vscode-prosemark-latex-integration— Extension host passesmathJaxPackageUrlfromwebview.asWebviewUri; webview usesurl-import.@prosemark/latex— RemovedmathJaxPackageUrlFromWebviewScript.static-import(disable a11y or copysre/).Dist layout