Skip to content

Inherit custom properties with var() already substituted - #276

Merged
eXpl0it3r merged 1 commit into
masterfrom
fix/custom-property-inheritance
Nov 10, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
fix/custom-property-inheritance

Conversation

@eXpl0it3r

Copy link
Copy Markdown
Collaborator

A custom property that references another one got inherited with its var() still in it, so the child substituted it against its own custom properties. With <div style="--a: red; --b: var(--a)"><p style="--a: blue; color: var(--b)"> the paragraph ended up blue, while it should be red, because the computed value of a custom property already has its variables substituted and that's what inherits (CSS Variables 1, section 2). The same applied to cycles, a custom property that's invalid on the parent could turn valid again on a child.

The cascade now resolves a box's custom properties to their computed values once all declarations are applied, before the deferred var() properties are resolved and before the children inherit them. Cyclic or otherwise invalid custom properties end up as the guaranteed-invalid value, i.e. they're dropped, so the child sees them as missing and uses the fallback.

How to test this PR?

CI should succeed. CustomProperty_IsInheritedWithVarSubstitutedOnTheParent, CustomProperty_IsInheritedWithVarSubstitutedOnEachAncestor and CyclicCustomProperty_IsInheritedAsGuaranteedInvalid in CustomPropertyTests cover the inheritance of resolved and invalid custom properties and fail on master. InheritedProperty_UsingVar_InheritsTheParentsResolvedValue checks that a regular inherited property using var() keeps the parent's value, which already worked.

@eXpl0it3r
eXpl0it3r force-pushed the fix/custom-property-inheritance branch from ff5e396 to 7cabe0a Compare November 10, 2026 19:06
@eXpl0it3r
eXpl0it3r merged commit e50c2e6 into master Nov 10, 2026
18 checks passed
@eXpl0it3r
eXpl0it3r deleted the fix/custom-property-inheritance branch November 10, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant