Skip to content

fix(core): keep the styles of a composition whose id contains $ patterns - #8141

Merged
miguel-heygen merged 2 commits into
mainfrom
secpub/compile-budget-core
Nov 18, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
secpub/compile-budget-core

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A composition whose id contains $&, $' or $` now keeps its styles in preview and render. Before, scoping a stylesheet to that composition pasted the matched text, or the rest of the selector, into the selector in place of the id, so the rule stopped matching its elements and the selector grew by the text around it. An id of a$'b turned [data-composition-id="a$'b"] .title into [data-composition-id="a .titleb"] .title.

Why

Scoping rewrites a selector naming the composition, or its root with data-start / data-duration, to the composition's own scope selector. It did that with String.prototype.replace(pattern, scope), and a replacement string reads $&, $', $` and $1 as patterns. The scope selector carries the composition id, which comes from the project's HTML, so those patterns in an id were expanded instead of written. The script that scopes a composition's own selectors at runtime made the same call with the same value.

Related work

None.

How

  • compositionScoping.ts: the three compile-time rewrites pass a function, () => scope, so the scope is inserted as text.
  • The runtime script emitted for each composition does the same through __hfRootSelectorText, used by its four replace calls.
  • The two page-build goldens embed that runtime script, so they change by those lines only.

Test plan

  • fails without the fix: "scopes the id %s exactly as a plain id, its $ kept as text" in packages/core/src/compiler/compositionScoping.test.ts (one case each for a$'b, a$`b and a$&b), the first commit. Without the fix all three fail; a$'b came out as [data-composition-id="a .titleb"] .title.
  • Linux box at the fix commit:
    • the new test passes 3 of 3 runs;
    • packages/core compiler and runtime pass 4,036 of 4,038 tests; the other 2 were the page-build goldens, which this branch now updates;
    • the core typecheck exits 0.
  • Not run locally: the updated goldens. Both test machines were unavailable, so I applied the same two-line change to both pages by hand (12 replacements and 3 declarations each, the querySelector(__hfRootSelector) call left alone). CI's pageBuild.golden.test.ts checks them.
  • Unit tests added/updated
  • Manual testing performed
  • Comments follow CONTRIBUTING.md "Comments"

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 50 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@terencecho terencecho 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.

Reviewed at f55c0c5. No blocking correctness, security, or data-loss finding.

All three compile-time replacements and four emitted runtime replacements insert the selector through callbacks, so replacement-string dollar sequences cannot reinterpret the composition id. The two golden updates match the emitted helper and callback changes.

Validation: full workspace build passed; all 90 composition-scoping and page-build golden tests passed. Reverting the compile-time callback changes makes all three named dollar-id regressions fail; restoring them passes. Three additional temporary runtime lookup probes also passed with an explicit mount selector. No real-browser render was performed. At the final check, three CI jobs were still running and none had failed.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 12a2f83 Nov 18, 2026
95 checks passed
@miguel-heygen
miguel-heygen deleted the secpub/compile-budget-core branch November 18, 2026 07:31
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.

2 participants