Skip to content

fix(scoping): rewrite prefix/substring composition-id selectors in place#2262

Open
Thomaswebstich wants to merge 1 commit into
heygen-com:mainfrom
Thomaswebstich:fix/scoper-prefix-selectors
Open

fix(scoping): rewrite prefix/substring composition-id selectors in place#2262
Thomaswebstich wants to merge 1 commit into
heygen-com:mainfrom
Thomaswebstich:fix/scoper-prefix-selectors

Conversation

@Thomaswebstich

Copy link
Copy Markdown

Problem

A sub-composition whose <style> scopes rules by a prefix/substring composition-id selector — [data-composition-id^="x"] (also *=, $=) — has those rules silently dropped when mounted in a multi-composition document.

scopeSelector() (in compositionScoping.ts) rewrites the exact [data-composition-id="x"] root selector in place to the instance scope, but any prefix/substring form falls through to the prepend branch and becomes a two-level selector:

[data-composition-id="x__hf2"] [data-composition-id^="x"] .thing

That now requires a nested composition-id element — but compositionLoader strips the inner root's data-composition-id at mount, so nothing matches and every class-scoped rule in that sub-comp stops applying (class-styled elements render unstyled). Single-mount renders keep the inner structure, so they're unaffected — the drop only shows when the loader renames/flattens (e.g. duplicate instances in one document).

This bites any authoring pipeline that rewrites ="x" to ^="x" so a sub-comp's own root rules survive the duplicate-instance rename (xx__hf2).

Fix

Widen the composition-id match to accept the substring operators (^=, *=, $=) of the authored id, so the authored-root selector is rewritten in place to the instance scope in every form — exactly like the exact = case — instead of being prepended.

One-line change to the selector regex, plus a regression test covering ^=/*=/$=.

Test

packages/core/src/compiler/compositionScoping.test.ts — new case asserts the prefix/substring forms are consumed in place (and never left intact behind a prepended scope). Full scoping suite passes.

🤖 Generated with Claude Code

scopeSelector() only rewrote the EXACT `[data-composition-id="x"]` root
selector in place; prefix/substring forms (`^=`, `*=`, `$=`) of the authored
composition id fell through to the prepend branch, becoming a two-level
`${scope} [data-composition-id^="x"] …` selector. That needs a NESTED
composition-id element, but the loader strips the inner root's composition-id
at mount, so the rule matches nothing and the sub-comp's class-scoped styles
silently drop (class-styled elements render unstyled).

This surfaces when a sub-comp ships prefix-match root selectors — e.g. an
authoring pipeline rewrites `="x"` to `^="x"` so rules survive the
duplicate-instance rename (x -> x__hf2). In a multi-scene document each such
sub-comp then loses its styling on mount, while single-mount renders (which
keep the inner structure) are unaffected.

Match the substring operators alongside `=` so the authored-root selector is
rewritten in place to the instance scope in every form. Adds a regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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