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

[lit-html] Add MathML support with the math template tag #4637

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

justinfagnani
Copy link
Collaborator

Fixes #4636

This adds a math template tag to enable writing MathML fragment templates, just like how we have the svg template tag for SVG fragment templates.

The change adds another TemplateResult type for MATHML, and just creates a <math> wrapper element for fragment templates like we do for SVG.

I had to update the @open-wc/testing dependency of the starter kits because 3.x had hard-coded the template result types. 4.x works with the new type. So there is the possibility that that this will break type-checking of other libraries that hard-code the types. Hopefully they can upgrade quickly if they need to. Our policy is to not consider type-only breaks as semver major, so this change is semver minor.

cc @lukewarlow @bkardell 😄

Copy link

changeset-bot bot commented May 2, 2024

🦋 Changeset detected

Latest commit: 3e852c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
lit-html Minor
lit Minor
lit-element Minor

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

Copy link
Contributor

github-actions bot commented May 2, 2024

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +6% (-0.15ms - +0.66ms)
    this-change vs tip-of-tree

render

  • this-change: 45.14ms - 47.03ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -7% - +0% (-1.35ms - +0.08ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +3% (-0.10ms - +0.85ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +3% (-0.17ms - +1.01ms)
    this-change vs tip-of-tree

update

  • this-change: 465.45ms - 472.63ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -11% - +1% (-4.21ms - +0.54ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +2% (-0.21ms - +1.29ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +1% (-2.28ms - +3.46ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 475.54ms - 480.24ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +1% (-1.10ms - +4.92ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
45.14ms - 47.03ms-

update

VersionAvg timevs
465.45ms - 472.63ms-

update-reflect

VersionAvg timevs
475.54ms - 480.24ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
17.96ms - 18.97ms-unsure 🔍
-7% - +0%
-1.35ms - +0.08ms
unsure 🔍
-4% - +4%
-0.73ms - +0.72ms
tip-of-tree
tip-of-tree
18.59ms - 19.61msunsure 🔍
-1% - +7%
-0.08ms - +1.35ms
-unsure 🔍
-1% - +7%
-0.10ms - +1.36ms
previous-release
previous-release
17.95ms - 18.99msunsure 🔍
-4% - +4%
-0.72ms - +0.73ms
unsure 🔍
-7% - +0%
-1.36ms - +0.10ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
35.29ms - 38.52ms-unsure 🔍
-11% - +1%
-4.21ms - +0.54ms
unsure 🔍
-8% - +5%
-2.86ms - +1.81ms
tip-of-tree
tip-of-tree
37.00ms - 40.48msunsure 🔍
-2% - +12%
-0.54ms - +4.21ms
-unsure 🔍
-3% - +10%
-1.12ms - +3.73ms
previous-release
previous-release
35.74ms - 39.12msunsure 🔍
-5% - +8%
-1.81ms - +2.86ms
unsure 🔍
-10% - +3%
-3.73ms - +1.12ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
10.80ms - 11.29ms-unsure 🔍
-1% - +6%
-0.15ms - +0.66ms
unsure 🔍
-0% - +8%
+0.01ms - +0.87ms
tip-of-tree
tip-of-tree
10.47ms - 11.12msunsure 🔍
-6% - +1%
-0.66ms - +0.15ms
-unsure 🔍
-3% - +6%
-0.29ms - +0.66ms
previous-release
previous-release
10.26ms - 10.96msfaster ✔
0% - 8%
0.01ms - 0.87ms
unsure 🔍
-6% - +3%
-0.66ms - +0.29ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
33.21ms - 33.99ms-unsure 🔍
-0% - +3%
-0.10ms - +0.85ms
unsure 🔍
-2% - +1%
-0.57ms - +0.40ms
tip-of-tree
tip-of-tree
32.95ms - 33.50msunsure 🔍
-3% - +0%
-0.85ms - +0.10ms
-faster ✔
0% - 3%
0.06ms - 0.86ms
previous-release
previous-release
33.39ms - 33.98msunsure 🔍
-1% - +2%
-0.40ms - +0.57ms
slower ❌
0% - 3%
0.06ms - 0.86ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
66.78ms - 68.01ms-unsure 🔍
-0% - +2%
-0.21ms - +1.29ms
unsure 🔍
-1% - +1%
-0.53ms - +0.98ms
tip-of-tree
tip-of-tree
66.44ms - 67.28msunsure 🔍
-2% - +0%
-1.29ms - +0.21ms
-unsure 🔍
-1% - +0%
-0.92ms - +0.29ms
previous-release
previous-release
66.73ms - 67.61msunsure 🔍
-1% - +1%
-0.98ms - +0.53ms
unsure 🔍
-0% - +1%
-0.29ms - +0.92ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
30.94ms - 31.84ms-unsure 🔍
-1% - +3%
-0.17ms - +1.01ms
unsure 🔍
-1% - +3%
-0.47ms - +0.79ms
tip-of-tree
tip-of-tree
30.59ms - 31.34msunsure 🔍
-3% - +1%
-1.01ms - +0.17ms
-unsure 🔍
-3% - +1%
-0.84ms - +0.32ms
previous-release
previous-release
30.79ms - 31.66msunsure 🔍
-3% - +1%
-0.79ms - +0.47ms
unsure 🔍
-1% - +3%
-0.32ms - +0.84ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
474.97ms - 479.22ms-unsure 🔍
-0% - +1%
-2.28ms - +3.46ms
unsure 🔍
-1% - +0%
-3.84ms - +1.99ms
tip-of-tree
tip-of-tree
474.57ms - 478.43msunsure 🔍
-1% - +0%
-3.46ms - +2.28ms
-unsure 🔍
-1% - +0%
-4.29ms - +1.26ms
previous-release
previous-release
476.02ms - 480.01msunsure 🔍
-0% - +1%
-1.99ms - +3.84ms
unsure 🔍
-0% - +1%
-1.26ms - +4.29ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
518.76ms - 523.41ms-unsure 🔍
-0% - +1%
-1.10ms - +4.92ms
unsure 🔍
-0% - +1%
-2.11ms - +4.71ms
tip-of-tree
tip-of-tree
517.26ms - 521.08msunsure 🔍
-1% - +0%
-4.92ms - +1.10ms
-unsure 🔍
-1% - +0%
-3.76ms - +2.53ms
previous-release
previous-release
517.29ms - 522.28msunsure 🔍
-1% - +0%
-4.71ms - +2.11ms
unsure 🔍
-0% - +1%
-2.53ms - +3.76ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link
Contributor

github-actions bot commented May 2, 2024

The size of lit-html.js and lit-core.min.js are as expected.

Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

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

Non-blocking, but maybe some cursory SSR tests would be nice?
e.g.

'ChildPart accepts TemplateResult with SVG type': {

test('svg fragment template', async () => {

Also, should there be an unsafeMath() directive, like unsafeSVG()?

packages/lit-html/src/lit-html.ts Outdated Show resolved Hide resolved
.changeset/beige-lamps-camp.md Show resolved Hide resolved
@justinfagnani
Copy link
Collaborator Author

@augustjk Thanks! I added unsafeMath() and SSR tests

@justinfagnani
Copy link
Collaborator Author

There's a small question of the name of the template tag. I chose math because I think it's a lot easier to read and write then mathml.

html, svg, and css are more clear about what their content are than just math, and that might help with built-in language support in tools. For instance, mathml might conceivable trigger XML or even MathML specific highlighting. math might not - though we can highlight it in our tools.

Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

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

Thanks!

Regarding the tag name, I have a preference for mathml as the full name of the markup language, but not strong enough to block. Maybe an online poll on discord or twitter?

If we do change, I suppose the unsafe directive name should change to unsafeMathML too.

@justinfagnani
Copy link
Collaborator Author

Regarding the tag name, I have a preference for mathml

Let's ask Discord before merging.

It's not unchangeable at least. Just a couple of byte cost to export two names.

@lukewarlow
Copy link

Math being the root element name for the MathML namespace makes me lean towards math as the tagged template name too fwiw.

@justinfagnani
Copy link
Collaborator Author

Math being the root element name for the MathML namespace makes me lean towards math as the tagged template name too fwiw.

That's a good point. <svg> -> svg, <math> -> math

@justinfagnani
Copy link
Collaborator Author

Discord seems to be leaning heavily towards mathml

scripts/check-size.js Outdated Show resolved Hide resolved
scripts/check-size.js Outdated Show resolved Hide resolved
Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

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

Change from math to mathml LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lit-html] MathML suppport
3 participants