You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(babel-plugin): remove split style and class object properties by identity - #5122
babel-plugin emits a residual _$style(el, { color: c() }, prev) (the computed key is gone and color is set twice), so prop() is never applied. The native compiler emits { [prop()]: v() }.
Both object splits in transformAttributes (dom/element.ts) walk a copy of the properties and remove each handled one with splice(index - i - 1, 1), after i has already been incremented. That index is negative for the first entries and counts from the end, so it removes the wrong entry, or nothing once it points past the end of the shrinking list. It only lands on the right entries when every property is extracted in a particular order. For styles, the computed key is removed and a plain key stays in the residual object. For classes, the list never empties, so the original object is kept on the element next to the split-out classes. Both now remove the handled property by identity, splice(list.indexOf(p), 1), the pattern the static-style pass in the same function already uses. The unused index parameters are dropped. The native compiler is unchanged.
Public API changes
None.
How did you test this change?
Added template108 (the style object above) to the shared __dom_fixtures__/attributeExpressions fixture and t6 (the class object above) to __dom_fixtures__/multipleClassAttributes; both are also read by the native compiler's parity suites. With element.ts reverted and the plugin rebuilt, dom.spec.js and dynamic-dom.spec.js fail on both fixtures, and the compiler's parity.test.js fails dom > attributeExpressions and dom > multipleClassAttributes. With the fix, babel-plugin passes (432) and the compiler suite passes (6937 passed, 2 skipped).
pnpm test from the repo root passes.
Verification
Compiled output for <div class={{ a: true, b: false, c: false, d: false }} style={{ color: c(), [prop()]: v(), background: b() }} /> with the published @solidjs/babel-plugin 2.0.2:
Rendered in jsdom with prop() returning "font-size", babel-plugin 2.0.2 gives {"color":"red","font-size":"","background":"blue"} and this branch gives {"color":"red","font-size":"20px","background":"blue"}, the same as the native compiler.
@codspeed/* 5.4.0 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.
System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
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
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.
Summary
@solidjs/babel-pluginmiscompiles someclassandstyleobjects in DOM output, where@solidjs/compilergets them right.A static
classobject with severalfalseentries leaves the object itself in the class attribute:compiles to
_$template()with babel-plugin 2.0.2, and to<div class=a>with the native compiler. Astyleobject loses a computed key that follows a dynamic property:babel-plugin emits a residual
_$style(el, { color: c() }, prev)(the computed key is gone andcoloris set twice), soprop()is never applied. The native compiler emits{ [prop()]: v() }.Both object splits in
transformAttributes(dom/element.ts) walk a copy of the properties and remove each handled one withsplice(index - i - 1, 1), afterihas already been incremented. That index is negative for the first entries and counts from the end, so it removes the wrong entry, or nothing once it points past the end of the shrinking list. It only lands on the right entries when every property is extracted in a particular order. For styles, the computed key is removed and a plain key stays in the residual object. For classes, the list never empties, so the original object is kept on the element next to the split-out classes. Both now remove the handled property by identity,splice(list.indexOf(p), 1), the pattern the static-style pass in the same function already uses. The unusedindexparameters are dropped. The native compiler is unchanged.Public API changes
None.
How did you test this change?
template108(the style object above) to the shared__dom_fixtures__/attributeExpressionsfixture andt6(the class object above) to__dom_fixtures__/multipleClassAttributes; both are also read by the native compiler's parity suites. Withelement.tsreverted and the plugin rebuilt,dom.spec.jsanddynamic-dom.spec.jsfail on both fixtures, and the compiler'sparity.test.jsfailsdom > attributeExpressionsanddom > multipleClassAttributes. With the fix, babel-plugin passes (432) and the compiler suite passes (6937 passed, 2 skipped).pnpm testfrom the repo root passes.Verification
Compiled output for
<div class={{ a: true, b: false, c: false, d: false }} style={{ color: c(), [prop()]: v(), background: b() }} />with the published@solidjs/babel-plugin2.0.2:With this branch (the same template and residual object as
@solidjs/compiler2.0.2):Rendered in jsdom with
prop()returning"font-size", babel-plugin 2.0.2 gives{"color":"red","font-size":"","background":"blue"}and this branch gives{"color":"red","font-size":"20px","background":"blue"}, the same as the native compiler.