Repository navigation
fix(compiler): include template contents when validating markup - #5126
Conversation
🦋 Changeset detectedLatest commit: 2b42d41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Merging this PR will improve performance by 31.59%3 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Summary
@solidjs/compilerrejects every<template>element that has content, in DOM and SSR, while@solidjs/babel-plugincompiles it:fails with "The HTML provided is malformed and will yield unexpected output when evaluated by a browser", and the full message shows why:
User HTML: <template><div>#text</div></template> Browser HTML: <template></template>.The native validator (
shared/validate.rs) parses the markup with html5ever and serializes it back withmarkup5ever_rcdom'sSerializableHandleto compare with the input. html5ever stores a template's nodes intemplate_contents, notchildren, and that serializer only walkschildren, so the "browser" side of every template is empty. Babel's validator serializes through parse5, which includes template content, and the two validators are meant to agree.A shared
serialize_treehelper, used by both the fragment and the document-shell validation paths, now copies each template'stemplate_contentschildren intochildrenbefore serializing. Valid templates compile again, and malformed markup inside a template still fails with the same diagnostic Babel reports.This fixes validation only. A template with dynamic parts (
<template><div>{x()}</div></template>, a custom element or a ref inside it) still fails at render time, because both compilers' DOM codegen walkstemplate.firstChildinstead of.content. That output is identical in babel-plugin 2.0.2 and this branch, so it is a separate codegen change for both compilers.Public API changes
None.
How did you test this change?
packages/compiler/__tests__/validate-parity.test.js, run in both the DOM and SSR tables: template text, a nested template, a template in<head>(the document-shell path), and<template><p><div>x</div></p></template>, which must still throw with Babel's diff. Withmain's binary 7 of the 34 tests fail; with the fix all 34 pass.cargo test,cargo clippy -- -D warningsand rustfmt onvalidate.rspass. The compiler vitest suite (6945 passed, 2 skipped), babel-plugin (432) andpnpm testfrom the repo root (39 of 39 turbo tasks) pass.Verification
A script that compiles each case with both compilers, renders the SSR output and the DOM template's
content. Published@solidjs/compiler2.0.2:This branch: