Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MathJax 3.2.0 Lazy Loading - mtd error #2788

Closed
bthomale opened this issue Oct 15, 2021 · 7 comments
Closed

MathJax 3.2.0 Lazy Loading - mtd error #2788

bthomale opened this issue Oct 15, 2021 · 7 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Fixed Test Needed v3 v3.2
Milestone

Comments

@bthomale
Copy link

bthomale commented Oct 15, 2021

Issue Summary

When using load: ['ui/lazy'] with mathml tables, some mtd elements load as yellow mtd text instead of loading correctly. When you load it without lazy typesetting, it renders just fine.

This is happening in a variety of browsers. I'm testing on macOS, looking at Safari, MS Edge, and FireFox.

Steps to Reproduce:

  1. Open the attached zip file.
  2. Open mtd-lazy-error.xhtml in Safari (or, any other browser).
  3. See the yellow mtd text in place of some of the cells.
  4. Open mtd-no-lazy-no-error.xhtml and see that it renders fine.

Technical details:

  • MathJax Version: 3.2.0
  • Client OS: macOS 11.6
  • Browser: Safari Version 15.0 (16612.1.29.41.4, 16612)
  • Browser: FireFox 93.0 (64-bit)
  • Browser: Microsoft Edge Version 94.0.992.50 (Official build) (x86_64)

Supporting information:

See attached zip archive for screenshots and sample xhtml.

MathJax-3.2.0-lazy-mtd-bug.zip

@dpvc
Copy link
Member

dpvc commented Oct 23, 2021

Thanks for the report. It turns out that this is due to the combination of XHTML, the m namespace, empty mtd elements, and lazy loading. Changing any one fo them lets it work.

The reason turns out to be that lazy loading causes the original MathML to be serialized and when it shows up again, it is re-parsed. But with the explicit m namespace in an XHTML document, the serialization is as XML, and so empty nodes use the <tag/> format rather than <tag></tag>. By default, MathJax's re-parsing is HTML parsing, and so those tags are not handled as self-closing tags, and the nesting structure gets corrupted.

You can tell MathJax to do xml parsing with the parseAs: 'xml' option in the mml configuration block, but it turns out there is an issue with that as well. In an XHTML document, the result of the XML parsing is not the same as in an HTML document, and MathJax ends up not finding the MathML properly.

Fortunately, there is an easy work-around. This configuration will allow your example to work properly in a lazy-loaded XHTML document:

  MathJax = {
    loader: {load: ['ui/lazy']},
    mml: {
      parseAs: 'xml'
    },
    startup: {
      ready() {
        const {HTMLAdaptor} = MathJax._.adaptors.HTMLAdaptor;
        HTMLAdaptor.prototype.body = function(doc) {return doc.body || doc};
        MathJax.startup.defaultReady();
      }
    }
  };

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Ready for Development v3 labels Oct 23, 2021
@bthomale
Copy link
Author

That seems to be working for me. Thanks!

@dpvc dpvc self-assigned this Jan 11, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Jan 18, 2022
@dpvc dpvc added this to the 3.2.1 milestone Jan 31, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Apr 6, 2022
Handle document created by parsing in XHTML.  (mathjax/MathJax#2788)
@dpvc dpvc added Merged Merged into develop branch Test Needed and removed Ready for Review labels Apr 6, 2022
@dpvc dpvc removed their assignment Jun 1, 2022
@dpvc dpvc added Fixed v3.2 and removed Merged Merged into develop branch labels Jun 1, 2022
@dpvc dpvc closed this as completed Jun 1, 2022
@bthomale
Copy link
Author

bthomale commented Jun 3, 2022

Hey guys, I am still able to reproduce this bug in MathJax 3.2.1. Here's an updated "reproducer" that points at the 3.2.1 sources in place of the 3.2.0 sources.

Can someone take another look?

The workaround you gave me at the top of this conversation (back in october) still works. I disabled the workaround to test the fix, but I'm afraid I've had to put it back in.

MathJax-3.2.1-lazy-mtd-bug.zip

@dpvc
Copy link
Member

dpvc commented Jun 3, 2022

You need to keep the

    mml: {
      parseAs: 'xml'
    },

because of the XHTML document. The stuff from the setup block is what was added in 3.2.1 and is no longer needed.

@bthomale
Copy link
Author

bthomale commented Jun 3, 2022

Oh! That helps. I'll give that a try.

@bthomale
Copy link
Author

bthomale commented Jun 3, 2022

That worked. Thanks! I had other startup logic I needed so it was just a matter of removing these two lines from it, I think:

        const {HTMLAdaptor} = MathJax._.adaptors.HTMLAdaptor;
        HTMLAdaptor.prototype.body = function(doc) {return doc.body || doc};

@dpvc
Copy link
Member

dpvc commented Jun 3, 2022

it was just a matter of removing these two lines from it, I think

Yes, that's right.

Glad that did it for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Fixed Test Needed v3 v3.2
Projects
None yet
Development

No branches or pull requests

2 participants