Skip to content

fix(core): report a <style> block rendered as an expression child (TSRX3014) - #1130

Merged
jonkwheeler merged 1 commit into
tsrx-org:mainfrom
jonkwheeler:fix/style-in-expression
Nov 12, 2026
Merged

jonkwheeler merged 1 commit into
tsrx-org:mainfrom
jonkwheeler:fix/style-in-expression

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A <style> block rendered as an expression child now reports TSRX3014 in the compiler, the editor and tsrx-tsc:

A <style> block inside an expression container, such as {<style>…</style>}, evaluates to its class map, so as a child it styles nothing. Remove the braces to write a standalone block in the element or fragment it styles: <><style>…</style><div>…</div></>. To reuse the block, assign it: const theme = <style>…</style>.

Before, <>…{<style>.feature-card { … }</style>}</> compiled without a diagnostic to the block's class-map object rendered as a child, and the siblings got no scope hash.

The rule covers a block that is the expression of a child expression container, directly, in parentheses, or as a branch of a conditional or logical expression ({ready && <style>…</style>}). A block whose value is used, such as an attribute value (theme={<style>…</style>}) or a member read ((<style>…</style>).a), is still an assigned block, and a plain-TSX <style>{css}</style> element is untouched.

The code is in the error table (DIAGNOSTIC_CODES.STYLE_IN_EXPRESSION_CONTAINER, TSRX_ERRORS.STYLE_IN_EXPRESSION_CONTAINER), the specification (the 5.1 static constraints, the style-block constraint list and the error-code appendix), the content-mapper error examples, and the regenerated MCP docs index. The nested-<style> half of #83 was already fixed on main by sibling-scoped style blocks.

Verification

  • packages/tsrx/tests/analyze/styles.test.js: four rejected shapes report TSRX3014 once at the block; attribute-value, member-read and conditional-member uses do not; a strict analysis throws it as fatal.
  • packages/tsrx/tests/utils/error-codes.test.js: TSRX3014 is reported and listed in the specification.
  • packages/content-mapper/tests/error-examples.test.js: the new example is reported once, with no TypeScript error on it, through classic tsrx-tsc and TypeScript 7.
  • The issue's playground source fails to compile with TSRX3014, and tsrx-tsc reports it.
  • npx vitest run --testTimeout=60000 (the default 5s timeout trips under machine load): 176 of 176 test files passed (10016 tests, 82 skipped) at d0224ad.
  • pnpm typecheck clean, pnpm changeset:check passes.

Related

Fixes #83

🤖 Generated with Claude Code


Note

Low Risk
Additive static analysis in the style pass; it only rejects patterns that previously compiled incorrectly, with no runtime or data-path changes.

Overview
<style> inside JSX expression children is now a compile error (TSRX3014) instead of silently emitting the block’s class-map object as a child (so siblings never got a scope hash).

The style analyzer adds is_rendered_expression_child, which flags a block when it is the value of {…} under an element or fragment—including through parentheses, && / ||, and conditional branches. Assigned uses (props, member reads, etc.) are unchanged.

TSRX3014 is wired through diagnostics, validation exports, specification/MCP docs, a content-mapper error example, and tests covering rejected shapes vs allowed value uses.

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

`{<style>…</style>}` in a children list is an expression, so the
analysis treated the block as an assigned one: it compiled to the
block's class-map object rendered as a child, and the siblings got no
scope hash (tsrx-org#83).

Report it as TSRX3014 when the block is the expression of a child
expression container, directly, in parentheses, or as a branch of a
conditional or logical expression. A block whose value is used, as an
attribute value or through a member read, is still an assigned block.
The code is in the error table and the specification, so the compiler,
the editor and tsrx-tsc report it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 27, 2026 10:57
@jonkwheeler
jonkwheeler merged commit 04ea4f0 into tsrx-org:main Nov 12, 2026
8 checks passed
jonkwheeler added a commit that referenced this pull request Nov 14, 2026
…nd inline elements (#1337)

* fix(website): build the site with a Ripple that keeps the spaces around inline elements

#1105 restored the spaces between words and inline code or links in the
website's sources, but the site still rendered most of them glued
("TSRX no longer has<code>&{ ... }</code>"): it builds with
`@ripple-ts/vite-plugin` 0.4.0, which pins `@tsrx/ripple` 0.2.0, and that
compiler drops a space at the edge of a multi-line text run. Ripple-TS/ripple
#1608 fixed the trim in `@tsrx/ripple` 0.2.8.

Move the Ripple packages the workspace builds with to the current release:
`ripple`, `@ripple-ts/vite-plugin` and `@ripple-ts/adapter-node` 0.6.1, whose
plugin uses `@tsrx/ripple` 0.2.11, and resolve the workspace's own
`@tsrx/ripple` to 0.2.11 as well. The catalog range of `@tsrx/ripple` stays
`^0.2.0`, so the optional peer range `@tsrx/typescript-plugin` publishes
doesn't change. The release-age exclusions for the 0.4.0/0.2.0 releases go
with them.

Also put back the one space the sources still lacked, before
`TSRX3014` in the specification (added by #1130 beside #1105).

Fixes #481

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.

[Bug]: TSRX <style> element inside an expression emits unexpected css

1 participant