Skip to content

fix(core): join a dynamic class with scope classes as each target renders it - #1232

Merged
jonkwheeler merged 19 commits into
tsrx-org:mainfrom
jonkwheeler:fix/scoped-class-value-forms
Nov 12, 2026
Merged

jonkwheeler merged 19 commits into
tsrx-org:mainfrom
jonkwheeler:fix/scoped-class-value-forms

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1168; review the commits after aac95f5; merge after #1168.

Summary

Beside scoped styles, an element's class now renders the way its target renders it without them, plus the scope classes. Solid and Vue also accept React-style className (#1216 cases 1–3; case 4 stays open, see below).

Source Target Before After
className={props.c}, c unset (or null, false) every target undefined tsrx-… tsrx-…
className={true} React, Hono DOM true tsrx-… tsrx-…
class={{ active: on }} Solid, Vue [object Object] tsrx-… active tsrx-…
class={['a', off && 'b', 'c']} Solid, Vue a,false,c tsrx-… a c tsrx-…
class={1}, or a function Solid 1 tsrx-…, function source tsrx-…
<div className="x" /> Solid, Vue classname="x", with or without styles class="x"
<div className={props.c} /> Solid, Vue ignored (Solid), classname attribute (Vue static) class={props.c}

How:

  • Per-target join. A new jsx.classValue platform option names how the runtime renders a class value. A class that may not be a string joins the scope classes through join_scope_class(value, scope, kind) from @tsrx/runtime/ref:
    • 'text' (React, Hono DOM) leaves out null, undefined, true and false.
    • 'text-true' (Preact) renders true as text.
    • 'text-both' (Hono's server) renders both booleans as text.
    • 'list' (Solid, Vue) keeps an object or a list and leaves out other values that are not strings.
    • Every other value joins as text.
    • fix(core): keep a host spread's class beside scoped style classes #1168's spread path uses the same kind on each target (merge_spread_class's last argument, which replaces hostSpreadClassList), so a Hono server spread's class: false prints false as plain Hono does.
    • A class that is always a string (a string or template literal, a choice between string literals, a concatenation, a $class read) still joins in the template literal, and the type-only print is unchanged.
  • className on Solid and Vue (your decision on case 3). A new jsx.rewriteClassNameAttr option, set by Solid and Vue, renames an intrinsic element's className to class before style scopes stamp it. This applies to static and dynamic values, with and without scoped styles.
    • Only a lowercase or namespaced tag is renamed. A dynamic <{Tag}> or member tag may be a component, so it keeps className; const Tag = Inner; <{Tag} className="x" /> passes className to Inner.
    • With one class and one className, they become one class: one string when both are string literals, otherwise [class, className].
    • With a spread between them, the runtime output renames className where it is written instead of joining it ahead of the spread. Each target then handles the two class attributes as written: Solid keeps the later one (b for class="a" {...{ class: 'bag' }} className="b"), and Vue's mergeProps joins them (a bag b).
    • Two className attributes stay two attributes, keeping TypeScript's duplicate-attribute error.
    • When several class attributes survive, the scope hash goes on the one that applies. On targets that read a spread's class themselves (Solid, React, Preact, Hono), that is the last one, except on Hono's server, which prints class and className apart; there it's the last one named like the first (a new jsx.classPropsPrintedApart option, set for Hono's server only). <p class="a" {...bag} className="b" /> beside a <style> renders b tsrx-… on Solid. On Vue, whose mergeProps joins them, it stays on the first: a tsrx-… fromBag b.
    • The type-only (editor) print renames it too, so it type-checks against the target's class. It gives the name a source_name, so the generated class maps back to the authored className with every editor feature (hover, rename, go-to-definition, diagnostics).
    • An element with both attributes type-checks as the runtime merge behaves. Across a spread, the type-only print still joins them, because TypeScript reports two class attributes even across a spread.
    • In a joined class, the second attribute's name maps to it as well, so hover and go-to-definition work on both authored names.
    • Component props, member and dynamic tags, and spread bags keep className, as at runtime. The targets' element types are unchanged.
  • Case 4 (a Vue spread bag's className) stays open. The previous head wrapped a Vue spread in merge_spread_class for its className, which broke SSR and reactivity. It printed a second class in Vue SSR, caused a hydration class mismatch for { className: undefined } beside a later class, and froze reactive() bags' keys. It is reverted (77a9cf3), and your decision covers authored attributes, not runtime bags.
    • So beside scoped styles, a spread bag { className: 'mine' } still renders only tsrx-… on the client, where plain Vue renders mine, and Vue SSR prints two class attributes.
    • mergeProps still joins a spread's class.
  • Vue helper imports. Vue's ensure_named_import added the helper to the first import of its module. That printed import * as r{ … } beside a namespace import, and put the helper in an import type that the build erases. It now joins only a named value import and otherwise adds an import of its own. (This predates the PR, but scoped classes now reach it.)

Output change: a class-map read such as class={theme.dark} is a string at runtime, but the compiler can't tell. It now compiles to __join_scope_class(theme.dark, "tsrx-…") (with "list" on Solid and Vue) and renders the same as before. The shared scoped-style tests, the conformance harness and the fixture README describe this; the fixture JSON is unchanged.

Known differences and follow-ups

  • Preact className={false} renders false natively and the scoped join leaves it out. class={false} is left out natively too. The kind is per target, not per attribute, so this one stays.
  • Hono's server css thenable keeps its own class but gets no scope hash, the same gap as fix(core): keep a host spread's class beside scoped style classes #1168's spread path. Joining it would need to resolve the promise; this is a follow-up.
  • Symbol and function classes on React: both render as text in the join, where React leaves them out.
  • A dynamic tag that resolves to a host element on Solid (<{tag} className="x" /> with tag = 'div') keeps className, which Solid renders as a classname attribute. A dynamic tag may be a component, so the compiler can't rename it. This was already true on main.
  • Hono's server with a spread bag beside class and className: in 4 of the 21 SSR shapes tested, the applied class still differs from plain Hono's, though it carries the hash. fix(core): keep a host spread's class beside scoped style classes #1168's merge_spread_class moves the bag's other-named class, and the order Hono prints depends on the bag's keys at runtime.

Verification

  • Runtime tests compare class={value} with and without a <style> sibling on all five targets.
    • Values: undefined, null, false, true, 0, '' and a string on every target; objects, lists, 1 and a function on Solid and Vue; a list on React.
    • Solid and Vue tests compare className with the matching class for a string, undefined and an object, alone, beside class and beside scoped styles, and check that no classname attribute remains. With the rewrite disabled, those 6 tests fail.
    • The Hono SSR test now compares with plain Hono, for undefined, null, false, true, '', 0 and a string.
  • The review's SSR probe (React, Hono, Solid and Vue; 11 values, expression and template forms) matches native plus one hash in all 88 cases.
  • Editor tests: a content-mapper test runs classic tsrx-tsc (TS 5.9) and native tsc (TS 7) on Solid and Vue projects. They use className="x", className={props.c}, class with className (also across a spread), a component's className prop, and a dynamic tag's.
    • Neither compiler reports an error. Before these fixes, both targets reported TS2322 on the authored className, and the dynamic tag and spread cases failed too.
    • On Solid, an intentional className={Symbol()} reports TS2322 at the authored className (line 14, column 6) under both compilers.
  • Several class attributes beside scoped styles: Solid and Vue runtime tests compare class and className around a spread, className first, and two classNames with the same element written natively, and expect one scope hash. On Solid they fail before d385b0e. Vue's output stays a tsrx-… fromBag b.
  • Review follow-up runtime tests (Solid and Vue):
    • A dynamic tag and a member tag receive className as written.
    • class="a" {...bag} className="b" renders as class="a" {...bag} class="b" does on each target.
    • Both fail on the previous head.
  • A Hono SSR test compares a spread's class with plain Hono, for the same values as the attribute.
  • Hono's server with class and className (f113350): a new SSR test checks that the hash goes on the class Hono prints first, and fails before; a Hono DOM test keeps it on the last attribute. Over 21 SSR shapes, the applied class has the hash in all 21 (3 before), and no shape that matched plain Hono stops matching. Hono DOM is unchanged (12 of 12).
  • Vue import tests cover a namespace import and a type-only import of @tsrx/vue/ref; both fail without the fix.
  • Compile tests:
    • The shared test checks each target's helper kind.
    • Solid and Vue tests cover the following, at runtime and in the type-only print:
      • className → class and the merged forms;
      • the in-place rename across a spread;
      • two className attributes;
      • component, member and dynamic tags;
      • the 9→5 mapping from className to class and its editor features.
    • React checks the unchanged type-only print.
    • Unit tests cover every kind, and merge_spread_class dropping numbers, true and functions in list mode.
  • Compile, runtime and vite-plugin suites for all five targets, plus tsrx-utils, content-mapper and typescript-plugin: 105 files, 6555 passed. The review's SSR probe still matches in all 88 cases. pnpm typecheck clean, prettier --check clean, pnpm changeset:check passes.
  • On f113350: tsrx-utils and the five targets' compile and runtime projects plus the Hono plugins, 5838 passed, 65 skipped; the other plugin projects, 100 passed. tsc (tsrx, tsrx-hono, tsrx-react, tsrx-solid, vite-plugin-hono, typecheck:tests) and Prettier are clean.

Related

Related: #1216 (cases 1–3; case 4, a Vue spread bag's className, stays open)
Related: #1168, #722

Cursor Bugbot

🤖 Generated with Claude Code


Note

Medium Risk
Cross-cutting JSX compile and runtime behavior for every first-party target; edge cases (booleans, objects, multiple class attributes, Hono SSR) change rendered output despite broad test coverage.

Overview
Scoped CSS class stamping now follows how each JSX runtime renders class / className, instead of always concatenating strings. The compiler routes non-trivial class values through join_scope_class and spread props through merge_spread_class, with per-target jsx.classValue (text, text-true, text-both, list) and spread options such as hostSpreadClassProps and classPropsPrintedApart (Hono server vs DOM).

That fixes cases where scoped output showed undefined tsrx-…, [object Object] tsrx-…, or dropped spread classes beside a <style> block; spreads after an authored class now keep spread class + scope hash on React, Preact, Solid, Hono, and Vue (Vue still relies on mergeProps for spreads rather than merge_spread_class).

Solid and Vue gain jsx.rewriteClassNameAttr: intrinsic elements compile authored className to class, including type-only output and source maps so the editor still understands className. Components, dynamic tags, and spread bags keep className as written; Vue spread bags with only className beside scoped styles remain a known gap.

Platform transforms, the style-scope pre-pass, shared conformance tests, and Vite plugin runtime/SSR suites are updated to lock in the new join semantics and imports for the helpers.

Reviewed by Cursor Bugbot for commit f113350. Bugbot is set up for automated code reviews on this repo. Configure here.

jonkwheeler and others added 7 commits October 27, 2026 10:15
…ope classes

merge_spread_class(props, scope_class, key, alias?) returns a bag without
a class as itself. Otherwise it returns a copy that reads the bag through
getters and carries the bag's class followed by the scope classes under
`key`. A class under `alias` moves to `key`, for runtimes that read either
prop. The bag is never written to, and Solid's lazy spread still tracks
each prop. A class object or list keeps its shape, as Solid's `class`
accepts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scoped styles stamped their class attribute after every spread, so the
attribute overwrote a class the spread passed. An authored class before a
spread kept the hash, and the spread overwrote both. Now, on a platform
with `jsx.hostSpreadClassProps`, the style pre-pass puts the stamped
attribute ahead of the spreads and wraps each spread after it in
merge_spread_class. The spread's class replaces only the authored class,
as in plain JSX, and the scope classes stay.

React reads `className`, Solid `class`, and Preact and Hono either one.
Vue's mergeProps already joins `class` across spreads, so Vue leaves its
spreads as written. Elements without a spread after the class attribute
compile as before, and so does the type-only output.

Fixes tsrx-org#722

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Solid

Review follow-ups for the host spread class merge:

- A bag with both class props reads the last one that has a value, as
  Preact and Hono render it. `{ class: 'x', className: undefined }` used
  to drop `x`.
- Only Solid, through the new `jsx.hostSpreadClassList`, joins a
  non-string class as `[class, scope]`. Elsewhere such a class applies
  unchanged, so Hono's `css` promise keeps working and React, Preact, and
  Hono no longer print `a,b,tsrx-…`.
- On Preact and Hono, a spread written before the class attribute drops
  its class props, so its `className` can no longer print a second class
  attribute in Hono SSR or replace the scope hash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ttribute

Outside Solid, a spread's non-string class now joins the scope classes as
`${class} ${scope}`, as the authored class attribute's template literal
does. Hono DOM's `css` object then keeps the scope hash, and a React list
class renders `a,b tsrx-…` either way. Only a thenable class, such as the
promise Hono's server `css` returns, still applies unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sses

It joins an element's authored class with its scope classes the way a
runtime whose class is text renders it: a `null`, `undefined`, `false` or
empty class is left out, a thenable applies unchanged, and any other value
joins as text. It shares `merge_spread_class`'s join.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…renders it

Scoped styles joined an authored class expression into a template literal,
so `className={props.c}` rendered `undefined tsrx-…` when `c` was unset, and
Solid's and Vue's object and list classes rendered `[object Object] tsrx-…`
and `a,false tsrx-…`. A class that may not be a string now joins through
`join_scope_class` on React, Preact and Hono, and as `[class, scope]` on
Solid and Vue, which set the new `jsx.classAttrList`. A class that is always
a string, and the type-only print, keep the template literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Vue sets a spread's `className` as a DOM property, which replaces the class,
so beside scoped styles `{ className: 'mine' }` rendered only the scope hash
or only `mine`, depending on key order. Vue now sets
`hostSpreadClassProps: ['className']`, so `merge_spread_class` appends the
scope classes to it. A spread before the class attribute is wrapped too when
its class prop has another name than the attribute, since that prop can
replace the class wherever it is written. Vue's `mergeProps` still joins a
spread's `class` itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/tsrx-react/src/transform.js Resolved
jonkwheeler and others added 10 commits October 27, 2026 17:55
This reverts d14ab95. Wrapping a Vue spread in `merge_spread_class` for its
`className` printed a second `class` attribute in Vue SSR, caused a hydration
class mismatch for `{ className: undefined }` beside a later `class`, and
froze the keys of a `reactive()` bag. A spread bag's `className` is runtime
data, so it is left to Vue again; `mergeProps` still joins a spread's `class`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`join_scope_class` takes a kind for how the runtime renders a class value:
`'text'` leaves out `true` as well as `null`, `undefined` and `false` (React,
Hono DOM), `'text-true'` renders `true` as text (Preact), `'text-both'`
renders both booleans as text (Hono's server), and `'list'` keeps only an
object or a list beside a string (Solid, Vue), leaving out numbers, `true` and
functions, which Solid renders as class names in a list. `merge_spread_class`'s
list mode gets the same `'list'` rule; its text join is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A new `jsx.classValue` platform option names how the runtime renders a host
element's class, and a class that may not be a string joins the scope
classes through `join_scope_class` with that kind: `'text'` on React and Hono
DOM, `'text-true'` on Preact, `'text-both'` on Hono's server, and `'list'` on
Solid and Vue, which replaces `classAttrList` and its inline array. So
`class={true}` no longer renders `true tsrx-…` on React, and `class={1}` or a
function class no longer becomes a class name on Solid. The runtime tests
compare each value with the target's own rendering, now including `true` and
`0`, and the Hono SSR test compares with plain Hono.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lass

Solid ignores `className`, and Vue renders a static one as a `classname`
attribute, so React-style source lost its class (and, beside scoped styles,
its scope hash). A new `jsx.rewriteClassNameAttr` option, set by Solid and
Vue, renames a host element's `className` to `class` before style scopes
stamp it. With both attributes, they join into one `class`: one string when
both are string literals, otherwise `[class, className]`. Component props,
spread bags and the type-only print keep `className` as written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The type-only print kept `className`, which Solid's and Vue's JSX types don't
have, so the editor reported TS2322 on source that now compiles. It renames
a host element's `className` to `class` too, and gives the name a
`source_name` so the generated `class` maps back to the authored `className`
with every editor feature. An element with both attributes type-checks as
the runtime merge does. Component props and spread bags keep `className`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`merge_spread_class` joined a spread's class with a fixed rule that kept
`true` as text and dropped `false`, so on Hono's server a spread's
`class: false` lost the `false` that plain Hono prints, and React kept a
`true` it leaves out. Its last argument is now the platform's `classValue`
kind, as for the class attribute, and replaces `hostSpreadClassList`: Solid's
spreads get `'list'` from `classValue`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pe import

`ensure_named_import` added the helper to the first import of its module. A
namespace import printed `import * as r{ … }`, and a type-only import was
erased from the build with the helper in it. Scoped classes now import
`join_scope_class` through it, so it only joins a named value import and
otherwise adds an import of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three review fixes to the Solid and Vue `className` rewrite:

- Only an intrinsic element (a lowercase or namespaced tag) is renamed. A
  dynamic `<{Tag}>` may be a component, so `const Tag = Inner; <{Tag}
  className="x" />` passes `className` to `Inner` again, at runtime and in
  the editor.
- With a spread between `class` and `className`, the runtime output renames
  `className` in place instead of joining it before the spread, so the last
  class written still wins. The type-only print still joins them, since
  TypeScript reports two `class` attributes even across a spread. Two
  `className` attributes stay two attributes, keeping TypeScript's
  duplicate-attribute error.
- In a joined `class`, the second attribute's name maps to it as well, so
  hover and go-to-definition work on both authored names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tely

With a spread between `class` and `className`, the runtime handles them as
two `class` attributes as written: Solid keeps the last one and Vue's
`mergeProps` joins them, so "the last class still wins" held only for Solid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On Solid, `class` and `className` around a spread (or two `className`s) stay
two `class` attributes, and Solid applies the last one, but scoped styles
stamped the first: `<p class="a" {...bag} className="b" />` rendered
`class="b"` without the scope hash. A runtime that reads a spread's class
itself (`hostSpreadClassProps`) now gets the hash on the last class
attribute. Vue, whose `mergeProps` joins them, keeps it on the first
(`a tsrx-… fromBag b`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d385b0e. Configure here.

Comment thread packages/tsrx/src/transform/scoping.js Resolved
Hono's server renderer prints `class` and `className` as two `class`
attributes, and a browser reads the first. Since d385b0e the scope
hash went on the last class attribute on every target that reads a
spread's class, so beside a `<style>`, `<span class="a" className="b" />`
printed `class="a" class="b tsrx-…"` and the browser applied `a`
without the hash.

A new `jsx.classPropsPrintedApart` platform option, set by Hono's server
mode, puts the hash on the last attribute named like the first one:
`class="a tsrx-…" class="b"`. Two attributes of one name still stamp
the last, which Hono prints (`class="a" {...bag} class="b"` gives
`class="b tsrx-…"`). Hono DOM applies the last attribute and keeps
d385b0e's choice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
main now has tsrx-org#1168's squash commit; merged against the parent commit this branch has so git doesn't redo that work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
@jonkwheeler
jonkwheeler merged commit 2473538 into tsrx-org:main Nov 12, 2026
8 checks passed
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
main now has tsrx-org#1232's squash commit; merged against the parent commit this branch has so git doesn't redo that work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
… now defers

Since main's tsrx-org#1232, Solid TSRX compiles a host element's className to class, which babel-preset-solid sets in an effect. Since tsrx-org#1107, it wraps a host spread in a normalize_spread_props call, so in a ternary arm (tsrx-org#246's shape) the compiler creates the element in an immediately called arrow. A yield in either place now leaves its generator, so TSRX2034 is right there. The downstream probes against the installed babel-preset-solid already agree.

Move both shapes to the reported list. The runtime test keeps a yield beside a host spread and a ref, on the returned element, which the compiler still evaluates in place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 12, 2026
* fix(solid, vue): report a yield in a template as TSRX2034

babel-preset-solid and vue-jsx-vapor move template expressions into
reactive effect callbacks. A `yield` there no longer runs in its
generator, so the build failed later with `A 'yield' expression is only
allowed in a generator body.` (or, for `yield*`, `The keyword 'yield' is
reserved`), pointing at compiled code.

Solid and Vue now set `validation.templateYieldUnsupported`, and core
reports each `yield` in a template as TSRX2034
(TARGET_TEMPLATE_YIELD_UNSUPPORTED) at the authored `yield`, in source
order: attribute values, children, spread values, component props,
directive heads and bodies, including `yield*`. A `yield` in a nested
function, or in the setup statements of a function's own `@{ … }` body,
stays allowed.

A reported `yield` is recorded so the shared checks for a `yield` in a
generated callback (TSRX2022) and for the `super` such a callback can't
read (TSRX2023) don't report it a second time. React, Preact and Hono
evaluate templates eagerly and don't set the flag.

The error gets a Solid example in `@tsrx/content-mapper`'s error
examples, and a line in the specification's code list.

Fixes #259

* fix(solid, vue): report TSRX2034 only where the target's compiler moves the yield

The previous commit reported every `yield` in a Solid or Vue template.
Some of them build today, because the target's JSX compiler leaves the
value in place, so the check now mirrors each compiler on TSRX's final
output, which is what that compiler reads.

Core runs the target's new `findDeferredTemplateYields` hook after the
generated closures are suspended, and reports what it returns. A
`yield*` that delegates to a generator made from a generated closure
now carries that generator in `metadata.generated_delegation`, and
stands for the authored `yield`s inside it. A `yield` that already has
an error at or inside it (TSRX2022, TSRX2023) gets no second one. The
source-level walk, the `templateYieldUnsupported` flag and the
`rejected_yields` set are gone.

- Solid (`template-yield.js`) follows babel-preset-solid's JSX compiler.
  An element returned or assigned as a whole, and the elements nested in
  it, are created in place; any other host element is created in an
  immediately called arrow. A dynamic value is evaluated in an effect,
  an inserted arrow or a prop getter, and a static one in place, using
  the compiler's own test (a member access, call, spread or `in`).
  `class` and `style` are always in an effect unless the value is an
  object literal. An array `ref` goes in an arrow; event handlers and
  other refs stay in place. An assignable component `ref` goes in a
  callback, and other component refs are passed on or dropped.
  Component children are passed in a getter when there are several, or
  one is an element or dynamic.
- Vue (`template-yield.js`) reports any `yield` in an element or
  fragment. vue-jsx-vapor creates every element in an immediately called
  arrow, but a host spread TSRX evaluates into a variable before the
  element stays allowed.

Checked against babel-preset-solid and vue-jsx-vapor on 4009 shapes per
target (contexts, positions, value kinds and TSRX directives): TSRX2034
appears exactly when the compiled output fails to parse. Exempt shapes
build and run in the Solid and Vue Vite runtime tests.

Related: #259

* test(core): skip only #246's no-error check on Solid and Vue

The previous commit skipped #246's whole shared block on Solid and Vue.
Only its check that the shapes compile without errors depends on the
target, since those targets report some of them as TSRX2034. The
mapping check and the `@for` body check still apply there. Keeping
the block's `describe` line as it was also lets this merge cleanly
with #1220's tests next to it.

Related: #259

* test(solid, vue): check TSRX2034 against the installed JSX compilers

The Solid rule mirrors dom-expressions' choices about which template
values it evaluates in place, and consumers get whatever compiler
their vite-plugin-solid brings. Two probe tests now run reported and
exempt shapes through TSRX, then the installed babel-preset-solid (as
vite-plugin-solid calls it) or vue-jsx-vapor, then Vite's TypeScript
strip. They assert that TSRX2034 appears exactly when the result fails
a strict module parse. The probes cover each branch of the rules: 43
for Solid and 17 for Vue. A compiler release that diverges now fails
CI instead of giving a false error.

The rules record the compiler versions they follow:
@dom-expressions/babel-plugin-jsx 0.50.0-next.44 (babel-preset-solid
2.0.0-rc.2) and vue-jsx-vapor 3.2.14.

Related: #259

* fix(solid): read TypeScript wrappers and ref calls as babel-preset-solid does

vite-plugin-solid hands babel the TypeScript as written, so
dom-expressions sees `as`, `satisfies` and `!` as ordinary expressions.
The Solid rule looked through them. As a result, it left out a returned
or declared element behind one (`return (<input title={yield t} />) as
any`), which the compiler creates in an immediately called arrow, and a
class or style object behind one, which goes in an effect. Both failed
the DOM build with no TSRX2034. The rule now looks through parentheses
only. The exceptions are where the compiler strips a wrapper itself: `as`
and `!` on a host ref, and `satisfies` too on a component ref.

A component whose `ref` is a call is created inside an immediately
called arrow, so every value on it is now deferred too. An optional
member ref, which the compiler drops, is left alone.

New guard probes: the TypeScript-wrapped elements and objects, the
component ref forms, and the Bugbot shapes (an assigned element, `open`,
`one` and a fragment inside the returned element). 6 of them fail on the
previous head.

Related: #259

* fix(solid): follow dom-expressions for spreads, select values and folded values

Four false reports and two misses in #1280's DOM rule, each checked
against the installed babel-preset-solid's DOM output:

- Beside a host spread, every attribute but `ref` is a prop of the
  spread: a dynamic one in a getter, any other in place. So
  `<div {...bag} class={yield t} />` builds and is no longer reported,
  and `<button {...bag} onClick={yield bag.onClick} />` fails and is.
- A `<select>`'s value, unless it's a literal, is assigned in a
  microtask as well as in place, so `<select value={yield t} />` is
  reported.
- The compiler folds a host attribute value, or a value in an object
  there, into a literal when it evaluates to a string, number or
  boolean, and a host child into text when it evaluates to a string or
  number. `title={{ a: yield t, b: 'x'.length }}` is static after that,
  and the `yield` in `title={false && (yield bag.x)}` is dropped. The
  rule reads only literals for this: templates, members of string and
  number literals, unary operators and short circuits on them.
- dom-expressions counts a tagged template as dynamic only as the whole
  value, so `title={(yield t) + tag`x`}` builds and is no longer
  reported.

* docs(changeset): describe the spread, select and folding rules

* fix(solid): split class and style objects as dom-expressions does

Codex found more false reports in the DOM rule's class and style
handling, each checked against the installed babel-preset-solid:

- dom-expressions splits a `class` object, and a `['static', { … }]`
  array, into one attribute per key, drops a key whose value it can
  evaluate, and sets each remaining key in an effect only if its value
  is dynamic. So `class={{ active: yield t, big: bag.big }}` builds.
  A computed key, or one with a space or colon, keeps the object
  whole, set in an effect, which the rule missed.
- It inlines a `style` key whose value is a string or number, drops a
  `null` or `undefined` one, and splits off the rest the same way; a
  computed key or a spread keeps the object whole.
- `className` is a plain attribute to it, set in an effect only when
  dynamic.
- babel evaluates a sequence to its last value, so
  `title={(yield bag.x, 'a')}` folds into a literal.

* fix(solid): read evaluated class and style values as dom-expressions does

A second Codex pass found false reports where dom-expressions sets a
`class` or `style` value in place because babel can evaluate it:
`class={null && (yield t)}`, a computed key like
`[(yield t, 'active')]`, and a class key holding an array it
evaluates. A whole `class` or `style` value, or what stays in a style
object, is now set in an effect only when it is dynamic or can't be
evaluated, and literal values cover arrays and objects. An object's
nested values are checked as part of the object, so a tagged template
inside one isn't dynamic.

* refactor(solid): drop a fold check that changes no result

A value that folds into a literal keeps no `yield`, since
`collect_folded_yields` drops them, so only an object's values need
folding in the dynamic test. Turning the check off failed no test.

* fix(solid): drop duplicate attributes and fold typeof a class

A third Codex pass found two more false reports: without a spread,
dom-expressions keeps only the last attribute of a name (but every
`ref`), so a `yield` in an earlier one is dropped; and babel evaluates
`typeof` a function or class to `'function'` without running it.

* fix(solid): rename stateful properties before dropping duplicates

dom-expressions renames a stateful property set to something other than
a literal (`value`, `checked`, …) to `prop:…` before it drops duplicate
attributes, so `<input value={yield bag.value} value="kept" />` keeps
both and moves the `yield` into an effect. The previous commit dropped
the first one and missed it (found by Codex).

* docs(changeset): describe the class, style and duplicate rules

* fix(solid): read stateful properties exactly as the compiler does

A fifth Codex pass found edge cases in the stateful-property names: the
compiler looks the tag up in upper case, doesn't count a RegExp or
BigInt as a literal, and folds a textarea's literal value into its
content, which removes that attribute before duplicates are dropped.

* fix(solid): skip children the compiler drops or replaces

Two false reports from the re-review, each checked against the DOM
build: a textarea's literal `value` or `defaultValue` (or a bare
`value`) replaces its children, so `<textarea value="x">{yield bag.t}</textarea>`
builds; and without a spread, a `children` attribute is dropped when
the element has children of its own, so
`<div children={yield bag.t}>x</div>` builds too.

* fix(solid): drop a children attribute on a void element

dom-expressions never writes children for a void element, so a
`children` attribute there is dropped too:
`<input children={yield bag.t} />` builds.

* test(solid): cover a children attribute on a void element

* fix(solid): report yields in kept class objects and listener data

Two misses from the re-review, each checked against the DOM build:

- A `class` object with a method or accessor keeps the whole object,
  which dom-expressions sets in an effect beside the split keys, so
  `class={{ a: yield t, b() { return 1; } }}` fails to build.
- On an event it doesn't delegate (`onScroll`, `on:click`), a
  `[handler, data]` array becomes `e => handler(data, e)`, so both
  elements move into a new listener; a third element is dropped.
  Delegated events keep both in place.

* docs(changeset): note the children and listener rules for TSRX2034

* fix(solid): skip void and noscript children, split any listener data

From a Codex pass on 0740ad7..6a35169, each checked against the
DOM build:

- dom-expressions writes no children for a void element or a
  `<noscript>`, so `<input>{yield bag.t}</input>` builds.
- A `[handler, data]` array on an event it doesn't delegate keeps only
  the first two elements whatever follows, so
  `onScroll={[bag.h, yield t, ...bag.e]}` fails; a spread for the data
  is passed as is. A hole or a spread handler, or a hole for the data,
  makes the compiler throw, so those stay unreported.

The changeset now names `defaultValue` and a bare `value` too.

* fix(solid): apply the drop rules to elements created in an arrow

From a second Codex pass, on 8b4cacc, each checked against the DOM
build:

- A host element the compiler creates in an immediately called arrow
  (a ternary arm, a fragment, a dynamic child) was reported whole, so
  what it drops was reported too: `t ? <input>{yield bag.t}</input> : null`
  builds. It's now walked like an inline element, with everything it
  keeps moved.
- A `children` attribute is also dropped on a `<noscript>` and beside a
  textarea's literal value, which writes its own children.

The exempt-shape test title now says the DOM output leaves the `yield`
in place or drops it.

* fix(solid): skip delegated event tails, $key and shadowed children props

From a third Codex pass, on bf62582, each checked against the DOM
build:

- The compiler keeps only the first two elements of an event array on
  a delegated event too, so `t ? <button onClick={[h, d, yield x]} /> : null`
  builds.
- A component's `children` prop is dropped when the component has
  children: `<Comp children={yield bag.t}>x</Comp>` builds.
- The DOM output removes an element's first `$key`:
  `<div $key={yield bag.k} />` builds.

A top-level `<svg xmlns={yield …}>` is left as a known gap.

* test(solid): report the className and spread-in-a-ternary yields main now defers

Since main's #1232, Solid TSRX compiles a host element's className to class, which babel-preset-solid sets in an effect. Since #1107, it wraps a host spread in a normalize_spread_props call, so in a ternary arm (#246's shape) the compiler creates the element in an immediately called arrow. A yield in either place now leaves its generator, so TSRX2034 is right there. The downstream probes against the installed babel-preset-solid already agree.

Move both shapes to the reported list. The runtime test keeps a yield beside a host spread and a ref, on the returned element, which the compiler still evaluates in place.

* fix(vue): evaluate a host spread that yields before the element

Main's #1108 binds Vue host spreads in place, as `{...(X = normalize(expr))}`, so vue-jsx-vapor's render effect reads the bag again when it changes. A `yield` in that bag would then run inside the effect, outside its generator, so TSRX2034 reported it and the runtime test's yielding spread stopped compiling.

A generator yields a value once, so an effect could never read a yielded bag again anyway. On a target that reports deferred template yields, a host spread whose bag yields keeps its setup declaration, evaluated before the element where the generator runs it, as every Vue spread was before #1108. Every other spread, including one beside it, is still bound in place, and React, Preact and Hono are unchanged. A new Vue test pins both forms.

* test(solid): report a yield in a static @for iterable now that main wraps it

Since main's #1134, Solid TSRX passes an @for iterable to `for_items(...)`, so `each={__for_items(yield t)}` is a call. babel-preset-solid reads such a <For> prop in a getter, where the `yield` no longer runs in its generator. The compiled output fails to parse, and the downstream probe against the installed babel-preset-solid agrees. TSRX2034 is right there now.

Move the case from "allows" to "reports", as with the className and #246 shapes. A yield in a static @if test still runs in place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
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.

1 participant