Skip to content

fix: merge styled host scope class with a spread class - #961

Merged
trueadm merged 2 commits into
mainfrom
cursor/styled-spread-class-582a
Sep 5, 2026
Merged

trueadm merged 2 commits into
mainfrom
cursor/styled-spread-class-582a

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #941.

Summary

  • A styled host with a spread and no authored class was appending a synthesized scope hash after the spread. Last-writer-wins then replaced props.class, so the spread class never reached the DOM. Client and SSR agreed on the wrong value.
  • Host-prop source resolution now treats a synthesized scope class as a merge onto the winning class identity, not a replacement. An authored class beside a spread is unchanged: its hash is still baked into that authored value and stays last-writer-wins.

Why

Changes

  • Compiler marks a synthesized class/className source with a trailing merge flag.
  • setHostPropSources and ssrAttrs apply that flag after identity last-writer-wins, composing via mergeClass.
  • Regression fixtures cover spread-only, authored-after-spread, authored-then-spread, alias last-writer, updates, SSR, and hydration.

Validation

  • pnpm format:check (CI lint on 7350af1f9)
  • pnpm typecheck (CI typecheck on 7350af1f9)
  • pnpm test (CI test (24) plus shards on 7350af1f9)
  • targeted tests: 24/24 scoped style+spread cases in style.test.ts (dev + prod); 264/264 across style.test.ts, clsx-class.test.ts, tsrx-features.test.ts, css-module-constants.test.ts (dev + prod projects)

Head 7350af1f9 is current with main (28907dbd8). Required and relevant checks are green. No review threads.

Risk / follow-ups

  • Merge work is gated on the synthesized-class flag, so ordinary spread/authored last-writer paths stay allocation-identical except that one extra boolean read on direct sources.
  • Authored class + spread last-writer-wins is intentionally unchanged, including the case where a later spread drops the baked-in hash.

Provenance

  • An agent produced this diff (agent-authored)
Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

A synthesized scope hash is no longer a later writer that replaces
props.class. Host-prop source resolution composes it onto the winning
class identity on both client and SSR.

Co-authored-by: Jon Wheeler <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 4, 2026
Keep the merge flag off the last-writer record path so TypeScript can
see pending class merges, and widen sibling source collectors to accept
the optional fourth tuple member.

Co-authored-by: Jon Wheeler <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review September 4, 2026 19:17
@trueadm
trueadm merged commit 20e2c96 into main Sep 5, 2026
48 checks passed
@trueadm
trueadm deleted the cursor/styled-spread-class-582a branch September 5, 2026 17:27
leonidaz added a commit that referenced this pull request Sep 5, 2026
Resolve against main's #957, #960, and #961, which landed on the
statement-scoped style machinery this branch replaces:

- runtime.ts: keep the branch's `injectStyle` (main's in-place refresh
  is already here; the React Float match stays a `data-href` token
  match for batched multi-hash islands).
- style-hmr-reinject.test.ts: take main's superset (adds the
  document-less case).
- compile.js / style-scopes.js: keep the sibling-scope pre-pass; drop
  main's `componentStyleRoots`/`annotateRootWithHash`/`applyCssScoping`
  and the `applyStyleRefs` import. Main's synthesized-class merge flag
  (#961) applies unchanged to the pre-pass's stamped attributes.
- `<style ref>` (#960) is not carried over: the attribute stays
  unsupported in Octane pending its removal from TSRX, so its fixture,
  tests, and changeset are dropped and the immutability fixture no
  longer uses it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Styled host without an authored class loses the class from a spread

3 participants