fix: warn on document-structure tags inside LWC template (#3681)#5835
Open
Berestly wants to merge 1 commit into
Open
fix: warn on document-structure tags inside LWC template (#3681)#5835Berestly wants to merge 1 commit into
Berestly wants to merge 1 commit into
Conversation
wjhsf
reviewed
Jul 13, 2026
| @@ -0,0 +1,6 @@ | |||
| <template> | |||
| <!doctype html> | |||
| <html></html> | |||
Contributor
There was a problem hiding this comment.
Can you add some tags with props? Also, what happens if there's more than one of a kind, since these are usually unique per document? What happens if there's an unmatched opening tag, or an unmatched closing tag?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi Team,
Fixes #3681
Details
When
<!doctype>,<html>,<head>, or<body>appear inside an LWC template,parse5collapses them into a text node. LWC'sparseTextNodere-reads the raw source (to avoid HTML entity decoding), which accidentally causes the literal tag markup to leak through and render as visible text on the screen.This PR updates
parseTextNodeto intercept these document-structure tags, strip them from the output so they don't render, and emit a specific warning diagnostic (LWC1214) per tag to notify the developer.Summary of Changes:
@lwc/errors: AddedDOCUMENT_STRUCTURE_TAG_NOT_ALLOWED_IN_TEMPLATE(Warning code1214) totemplate-transform.tsand bumped the next error code marker to1215inindex.ts.@lwc/template-compiler: Added matching regex rules inconstants.tsand wired them intoparseTextNodeinsideparser/index.ts.disallowed-document-structure-tags) verifying that the compiler cleanly strips out the invalid markup and emits four individualLWC1214warnings.Does this pull request introduce a breaking change?
🗿 No, it does not introduce a breaking change.
Does this pull request introduce an observable change?
✅ Yes, it does include an observable change.
Anticipated Observable Changes:
LWC1214compiler warning in the console if they include document-level tags inside an LWC template.<html>) will no longer render onto the viewport at runtime.GUS work item
W-18040860
Thanks!