Skip to content

fix: [#2344] Resolve every var() in a value, not only the first one - #2395

Open
klaesra wants to merge 1 commit into
capricorn86:masterfrom
klaesra:fix/2344-resolve-all-css-variables
Open

fix: [#2344] Resolve every var() in a value, not only the first one#2395
klaesra wants to merge 1 commit into
capricorn86:masterfrom
klaesra:fix/2344-resolve-all-css-variables

Conversation

@klaesra

@klaesra klaesra commented Sep 8, 2026

Copy link
Copy Markdown

Description

Since v20.12.1 CSSVariableFormatter.resolveVariables() substitutes the first var() it finds and returns, leaving the rest of the value untouched. calc(5 * var(--box) + 6 * var(--gap)) computes to calc(5 * 20px + 6 * var(--gap)), and a shorthand such as padding: calc(0.375 * var(--x)) calc(0.75 * var(--x)) fails validation and is dropped from getComputedStyle() together with its longhands.

The remainder of the value is now passed through resolveVariables() as well, so every var() is substituted; nested fallbacks are unchanged. Browsers substitute all occurrences at computed-value time (Chromium returns the resolved length, as noted in #2351).

Resolves #2344
Resolves #2351

Before submitting the PR, please make sure you do the following:

Tests

  • Two tests in CSSComputedStyle.test.ts: a calc() with two variables (and the same variable twice), and a shorthand with var() fallbacks after an earlier var(). Both fail on master and pass with the fix.
  • npm test run locally; the only failures are pre-existing Windows-environment tests (virtual server, module loader, timers, file cache) that fail identically on master.

AI tools

  • Written with Claude Code (Anthropic), reviewed and verified by the submitter.

@klaesra
klaesra requested a review from capricorn86 as a code owner September 8, 2026 09:36
…first one

Since v20.12.1 resolveVariables() substituted the first var() and returned,
leaving later occurrences in the value unresolved. The remainder of the value
is now resolved as well.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@klaesra
klaesra force-pushed the fix/2344-resolve-all-css-variables branch from 291d34c to 8ef97cf Compare September 8, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant