-
Notifications
You must be signed in to change notification settings - Fork 396
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(ssr): correctly render foreign namespace element closing tags #4992
fix(ssr): correctly render foreign namespace element closing tags #4992
Conversation
packages/@lwc/engine-server/src/__tests__/fixtures/render-correct-closing-tags/expected.html
Outdated
Show resolved
Hide resolved
const isForeignElement = node.namespace !== HTML_NAMESPACE; | ||
const hasChildren = childContent.length > 0; | ||
|
||
if (isForeignElement && !hasChildren) { |
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.
Are there any non-HTML elements that are not self-closing when empty?
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.
I don't think so, or at least I couldn't find any SVG or MathML cases. The spec just says "Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag." but that is not exactly what you are asking.
const hasChildren = childContent.length > 0; | ||
|
||
if (isForeignElement && !hasChildren) { | ||
return [bYield(b.literal(`<${node.name}`)), ...yieldAttrsAndProps, bYield(b.literal(`/>`))]; |
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.
This could be merged as a ternary in the return statement below.
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.
I also removed the separate return for void html elements and they return here too. They were also missing the scope class and failed the test once that was added.
@@ -0,0 +1,19 @@ | |||
<template> |
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.
Add test cases for class
attribute and lwc:inner-html
on input or textarea or somthing.
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.
Adding lwc:inner-html
to a void element like input throws an exception in v1 (engine-server) and renders nothing so I didn't add it. For v2 it doesn't throw but it doesn't render anything. Should we open an issue or make a change to throw when inner-html
is used on void elements? Or is it enough that it is a sort of noop
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.
We should open an issue to make it throw an error. lwc:inner-html
doesn't make any sense for void elements, so throwing an error is a good behavior.
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.
Ok sounds good, I opened this issue
<svg> | ||
<pattern lwc:inner-html={foreignNamespaceInnerHtml}></pattern> | ||
<image xlink:title="title"></image> | ||
</svg> |
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.
It'd be great to add a MathML block here for completeness.
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.
including <math>
namespace elements passed for ssr-compiler
but generates a warning when engine-server
fixtures are ran as it appears MathML elements are not recognized as a knownTag by template-compiler -> validateElement. To enable testing MathML for both I suppressed the warning here.
Is that OK or would you rather modify template-compiler -> validateElement to recognize MathML elements, or...?
I suppose it could be argued that the same warning / tag-check should be there for @lwc/ssr-compiler too, or not needed? I'm not sure as tags used in the correct namespace shouldn't really generate a warning, so should we be reproducing this behavior in v2 regardless?
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.
Yep, opened an issue for this: #5010
MathML should be supported.
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.
Ok thanks, seems wrong. I updated the warning suppression in the fixture to reference the issue you opened.
bYield(b.literal(`>`)), | ||
...childContent, | ||
bYield(b.literal(`</${node.name}>`)), | ||
isForeignSelfClosingElement ? bYield(b.literal(`/>`)) : bYield(b.literal(`>`)), |
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.
isForeignSelfClosingElement ? bYield(b.literal(`/>`)) : bYield(b.literal(`>`)), | |
bYield(b.literal(isForeignSelfClosingElement ? `/>` : `>`)), |
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.
LGTM
code === 'CIRCULAR_DEPENDENCY'; | ||
code === 'CIRCULAR_DEPENDENCY' || | ||
// template-compiler -> index -> validateElement generates UNKNOWN_HTML_TAG_IN_TEMPLATE for MathML elements | ||
message.includes('LWC1123'); |
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.
This is bizarre... we should fix this.
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.
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, updated the comment with a TODO on that issue.
</mi> | ||
<mo class="lwc-4q9u0sqsfc0"> | ||
| ||
</mo> |
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.
It'd be great to have an example of a self-closing tag in MathML to make sure we do it correctly.
Also ⁢
is very confusing here since it renders invisibly. Tricked me into thinking that this should be self-closing when it isn't.
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.
Wait – this should be self-closing, right? Since it's actually just a comment?
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.
Wait – this should be self-closing, right? Since it's actually just a comment?
I'm not sure... it is actually appearing as an invisible character aka ZWJ (yellow box) in Visual Studio in both the component and the expected output? It passes in both engine-server and ssr-compiler (not to say that means it is correct). It is a confusing example though and I can remove it.
It'd be great to have an example of a self-closing tag in MathML to make sure we do it correctly.
Sorry I didn't add that. Unfortunately we have another engine-server
bug here...
<plus/>
and<plus></plus>
is rendered as<plus></plus>
byengine-server
<plus/>
and<plus></plus>
is rendered as<plus/>
byssr-compiler
(expected output)
Shall I open another issue?
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.
I missed that there is literally an invisible character in there, outside of the comment. Yeah I would switch to something that's visible.
Shall I open another issue?
Yes, I would open a bug for this. All non-HTML childless components should render as self-closing (with the />
).
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.
Ok sounds good, opened #5015 on engine-server, referenced it in the example and removed the invisible character example
cf45746
to
8d6d2e4
Compare
Details
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item
W-16871512