fix(scoping): rewrite prefix/substring composition-id selectors in place#2262
Open
Thomaswebstich wants to merge 1 commit into
Open
fix(scoping): rewrite prefix/substring composition-id selectors in place#2262Thomaswebstich wants to merge 1 commit into
Thomaswebstich wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()(incompositionScoping.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:That now requires a nested composition-id element — but
compositionLoaderstrips the inner root'sdata-composition-idat 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 (x→x__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