-
Notifications
You must be signed in to change notification settings - Fork 398
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
Merged
jhefferman-sfdc
merged 8 commits into
master
from
jhefferman/ssr/foreign-element-render-void-fix
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7287465
fix: correctly render foreign element closing tags
jhefferman-sfdc 6ea8218
fix: properly handle scoped class for void and foreign elements
jhefferman-sfdc 66b4a37
fix: address review comments
jhefferman-sfdc ff5fe94
fix: remove math example for now
jhefferman-sfdc 35d5797
fix: ignore UNKNOWN_HTML_TAG_IN_TEMPLATE warning to allow for MathML โฆ
jhefferman-sfdc 8d6d2e4
fix: update tag warning suppression to reference issue
jhefferman-sfdc 5c6bfe6
fix: simpler MathML example
jhefferman-sfdc 0cab84d
chore: merge master
jhefferman-sfdc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: properly handle scoped class for void and foreign elements
- Loading branch information
commit 6ea8218cf8ba13627e7890613255506371e9c134
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
packages/@lwc/engine-server/src/__tests__/fixtures/render-correct-closing-tags/expected.html
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...-server/src/__tests__/fixtures/render-correct-closing-tags/modules/x/elements/elements.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
packages/@lwc/engine-server/src/__tests__/fixtures/render-correct-tags/expected.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<x-elements class="lwc-4q9u0sqsfc0-host" data-lwc-host-scope-token="lwc-4q9u0sqsfc0-host"> | ||
<template shadowrootmode="open"> | ||
<style class="lwc-4q9u0sqsfc0" type="text/css"> | ||
:host {background: blue;} | ||
</style> | ||
<a class="lwc-4q9u0sqsfc0" href="https://www.salesforce.com/"> | ||
</a> | ||
<label class="lwc-4q9u0sqsfc0" for="textInput"> | ||
Some input | ||
</label> | ||
<input class="lwc-4q9u0sqsfc0" id="textInput" type="text"> | ||
<svg class="lwc-4q9u0sqsfc0"> | ||
<pattern class="lwc-4q9u0sqsfc0"> | ||
<image class="lwc-4q9u0sqsfc0" xlink:href="https://www.salesforce.com/"/> | ||
</pattern> | ||
<image class="lwc-4q9u0sqsfc0" xlink:title="title"/> | ||
</svg> | ||
<svg class="lwc-4q9u0sqsfc0"> | ||
<pattern class="lwc-4q9u0sqsfc0"> | ||
<image xlink:href="https://www.salesforce.com/"> | ||
</image> | ||
</pattern> | ||
<image class="lwc-4q9u0sqsfc0" xlink:title="title"/> | ||
</svg> | ||
</template> | ||
</x-elements> |
File renamed without changes.
This file contains 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
5 changes: 5 additions & 0 deletions
5
...c/engine-server/src/__tests__/fixtures/render-correct-tags/modules/x/elements/elements.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class extends LightningElement { | ||
@api foreignNamespaceInnerHtml = '<image xlink:href="https://www.salesforce.com/"></image>'; | ||
} |
3 changes: 3 additions & 0 deletions
3
...-server/src/__tests__/fixtures/render-correct-tags/modules/x/elements/elements.scoped.css
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
background: blue; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -227,10 +227,6 @@ export const Element: Transformer<IrElement | IrExternalComponent | IrSlot> = fu | |||||
return result; | ||||||
}); | ||||||
|
||||||
if (isVoidElement(node.name, HTML_NAMESPACE)) { | ||||||
return [bYield(b.literal(`<${node.name}`)), ...yieldAttrsAndProps, bYield(b.literal(`>`))]; | ||||||
} | ||||||
|
||||||
let childContent: EsStatement[]; | ||||||
// An element can have children or lwc:inner-html, but not both | ||||||
// If it has both, the template compiler will throw an error before reaching here | ||||||
|
@@ -246,20 +242,17 @@ export const Element: Transformer<IrElement | IrExternalComponent | IrSlot> = fu | |||||
childContent = []; | ||||||
} | ||||||
|
||||||
const isForeignElement = node.namespace !== HTML_NAMESPACE; | ||||||
const hasChildren = childContent.length > 0; | ||||||
|
||||||
if (isForeignElement && !hasChildren) { | ||||||
return [bYield(b.literal(`<${node.name}`)), ...yieldAttrsAndProps, bYield(b.literal(`/>`))]; | ||||||
} | ||||||
const isForeignSelfClosingElement = | ||||||
node.namespace !== HTML_NAMESPACE && childContent.length === 0; | ||||||
const isSelfClosingElement = | ||||||
isVoidElement(node.name, HTML_NAMESPACE) || isForeignSelfClosingElement; | ||||||
|
||||||
return [ | ||||||
bYield(b.literal(`<${node.name}`)), | ||||||
// If we haven't already prefixed the scope token to an existing class, add an explicit class here | ||||||
...(hasClassAttribute ? [] : [bConditionallyYieldScopeTokenClass()]), | ||||||
...yieldAttrsAndProps, | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
...(isSelfClosingElement ? [] : [...childContent, bYield(b.literal(`</${node.name}>`))]), | ||||||
].filter(Boolean); | ||||||
}; |
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.
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 forssr-compiler
but generates a warning whenengine-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.