Skip to content

fix(babel-plugin): remove split style and class object properties by identity - #5122

Merged
ryansolid merged 1 commit into
solidjs:mainfrom
Marve10s:fix-babel-computed-style-key
Nov 20, 2026
Merged

ryansolid merged 1 commit into
solidjs:mainfrom
Marve10s:fix-babel-computed-style-key

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Summary

@solidjs/babel-plugin miscompiles some class and style objects in DOM output, where @solidjs/compiler gets them right.

A static class object with several false entries leaves the object itself in the class attribute:

<div class={{ a: true, b: false, c: false, d: false }} />

compiles to _$template(

) with babel-plugin 2.0.2, and to <div class=a> with the native compiler. A style object loses a computed key that follows a dynamic property:

<div style={{ color: c(), [prop()]: v(), background: b() }} />

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:

var _tmpl$ = /*#__PURE__*/_$template(`<div class="[object Object] a">`);
// ...
  _$effect(() => ({
    e: {
      color: c()
    },
    t: c(),
    a: b()
  }), ...

With this branch (the same template and residual object as @solidjs/compiler 2.0.2):

var _tmpl$ = /*#__PURE__*/_$template(`<div class=a>`);
// ...
  _$effect(() => ({
    e: {
      [prop()]: v()
    },
    t: c(),
    a: b()
  }), ...

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.

@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dcdc9ca

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/babel-plugin Patch

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

@codspeed

codspeed Bot commented Nov 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

2 warnings

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@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.

See affected benchmarks

⚠️ 1 benchmark is dominated by system calls

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.

Learn more about system calls

See affected benchmarks

✅ 201 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing Marve10s:fix-babel-computed-style-key (dcdc9ca) with main (99db9bc)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@ryansolid
ryansolid merged commit 8de0cfd into solidjs:main Nov 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants