-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(auto-render): concatenate content of successive text nodes #3422
Conversation
Concatenate successive text nodes to prevent auto-render from skipping math input when browsers split text nodes with long textContent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/67738121/in-what-cases-do-browsers-create-multiple-adjacent-text-nodes seems to confirm this issue; do you have other documentation, or an example where this is failing?
Overall, this seems like a good idea, though potentially slow/inefficient, better than not working. But we need to not touch such text if it has no math expressions in it; see comment.
Only remove siblings when math expressions were found to prevent removal of nodes that do not contain math.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks -- this is looking good! Would you be able to add tests to contrib/auto-render/test/auto-render-spec.js
? If not, I can try.
Codecov Report
@@ Coverage Diff @@
## main #3422 +/- ##
==========================================
+ Coverage 92.98% 93.00% +0.02%
==========================================
Files 90 90
Lines 6739 6750 +11
Branches 1568 1570 +2
==========================================
+ Hits 6266 6278 +12
+ Misses 435 434 -1
Partials 38 38
Continue to review full report at Codecov.
|
I'm working on a test with two strings long enough to break on Chrome (including and not including math to render). I'm not familiar enough with jest to know if it's possible to reproduce the issue in a unit test since the problem is browser-specific. My tests pass with the current version of katex as well, so I could provide a much smaller string if a browser-specific test is not possible. |
I'm not sure what DOM the tests use, but it might be virtual. I had in mind tests where you manually make multiple adjacent text nodes, not necessarily large, and make sure the right substitutions happen (or don't happen). |
That makes a lot more sense than what I was trying to do. The current tests should do the trick. The math parser fails in the current KaTeX version but passes with my mods. |
Thank you for the PR! |
🎉 This PR is included in version 0.16.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Webkit-based browsers like Chrome, Edge, or Safari do not parse very large math expressions (limit appears to be around 48k characters) because they split large text nodes into smaller ones so that auto-render misses delimiters. This PR fixes this by concatenating all successive text nodes.
Tested on:
What is the previous behavior before this PR?
Webkit-based browsers (Chrome, Edge, Safari) split large text nodes into smaller ones. This can cause delimiters to be in separate child nodes, which the auto-render parser will miss.
What is the new behavior after this PR?
All successive text modes will be concatenated into one node and the concatenated textContent will be used to render math.