Repository navigation
fix(compiler): skip noscript children in client DOM output, matching babel-plugin - #5116
Conversation
🦋 Changeset detectedLatest commit: 67d96b1 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 degrade performance by 5.35%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Summary
@solidjs/compilerrenders<noscript>content on the client in cases where@solidjs/babel-plugindoes not. With the usual Google Tag Manager fallback:the native compiler puts the iframe into the client template and binds its
src, so in a browser with JavaScript on, the iframe is created and loads, and it loads again wheneverid()changes. In jsdom (vitest), the template's noscript content parses as text, so the generated_el$.firstChildis a Text node andsetAttributethrowsnode.setAttribute is not a function, which halts reactivity.babel-plugin never lowers noscript children (
if (tagName !== "noscript") transformChildren(...)indom/element.ts), following #2178 ("we never wantnoscriptcontent to render on the client"). The native compiler already skips them instatic_template.rsfor a fully static nested<noscript>, but its other two paths do not: a<noscript>that is the template root (dom/element.rs), and a nested<noscript>that has its own dynamic attribute, spread or ref and so is not static (dom/children.rs). Both now skiplower_dom_childrenfornoscript, the same gate babel uses. Attributes and spreads on the<noscript>itself still bind, and SSR output is unchanged.Public API changes
None.
How did you test this change?
simpleElementsfixtures (__dom_fixtures__and__dom_hydratable_fixtures__): a root<noscript>with a dynamic iframesrc, and a nested<noscript>with a dynamicdata-idand a dynamic child. babel-plugin's source is unchanged, so its expected output comes from the current plugin; the native compiler's expected outputs were regenerated. Withmain's compiler binary, 43 compiler tests fail on these fixtures (babel-fixtures, dom-hydratable-fixtures, parity, cross-mode-parity and option-matrix), for example+ var _tmpl$6 = _$template(<iframe height=0 width=0>)against babel's<noscript>. With the fix all compiler tests pass (6951) and babel-plugin passes (432).cargo testandcargo clippy -- -D warningspass.pnpm testfrom the repo root passes (39 of 39 turbo tasks).Verification
Compiled output for
<noscript><iframe src={"/ns.html?id=" + id()} /></noscript>with the published@solidjs/compiler2.0.2:and with babel-plugin 2.0.2, and with this branch's native compiler (identical):
Rendered in headless Chromium with 2.0.2, then setting the id from
AtoB:In jsdom with 2.0.2 the native-compiled root and nested cases throw
node.setAttribute is not a function; with this branch every case renders the same as babel (<noscript></noscript>,<div><noscript data-k="l"></noscript></div>).