Skip to content

Handle global keywords in CSS shorthand property handlers#4117

Merged
domenic merged 1 commit intomainfrom
border-global-keyword-fix
Mar 19, 2026
Merged

Handle global keywords in CSS shorthand property handlers#4117
domenic merged 1 commit intomainfrom
border-global-keyword-fix

Conversation

@domenic
Copy link
Copy Markdown
Member

@domenic domenic commented Mar 19, 2026

Several shorthand property handlers (border, background, and their sub-shorthands) crashed or produced incorrect results when encountering CSS-wide keywords like "inherit" or "initial". The root cause is that parse() functions return strings for global keywords, but many callers assumed object/array returns.

  • In processBorderProperties, handle global keywords uniformly at the top of the loop before any property-specific branching, fixing cssText = "border-top: inherit" (and all border side/line shorthands) which previously threw a TypeError swallowed by the cssText setter's catch block.
  • In matchesBorderShorthandValue, return false for non-object parse results, fixing border: inherit followed by setting a longhand like borderTopWidth.
  • In prepareBorderStringValue and prepareBorderObjectValue, guard replacePositionValue calls against global keyword inputs, fixing border: inherit followed by setting a sub-shorthand like borderTop.
  • In background.parse(), return global keywords as strings (matching border.parse() behavior). Update the descriptor setter to propagate them to all longhands and the getter to verify longhand consistency before returning.
  • In prepareProperties, skip replaceBackgroundShorthand for global keyword shorthands, and fix a pre-existing Map mutation-during-iteration bug by updating parsedProperties instead of properties.
  • Mark cssom-setProperty-shorthand.html as passing.

@asamuzaK after merging d589a8e I asked Claude if it could find any similar issues and this is what it found. WDYT?

Several shorthand property handlers (border, background, and their sub-shorthands) crashed or produced incorrect results when encountering CSS-wide keywords like "inherit" or "initial". The root cause is that `parse()` functions return strings for global keywords, but many callers assumed object/array returns.

- In `processBorderProperties`, handle global keywords uniformly at the top of the loop before any property-specific branching, fixing `cssText = "border-top: inherit"` (and all border side/line shorthands) which previously threw a TypeError swallowed by the cssText setter's catch block.
- In `matchesBorderShorthandValue`, return false for non-object parse results, fixing `border: inherit` followed by setting a longhand like `borderTopWidth`.
- In `prepareBorderStringValue` and `prepareBorderObjectValue`, guard `replacePositionValue` calls against global keyword inputs, fixing `border: inherit` followed by setting a sub-shorthand like `borderTop`.
- In `background.parse()`, return global keywords as strings (matching `border.parse()` behavior). Update the descriptor setter to propagate them to all longhands and the getter to verify longhand consistency before returning.
- In `prepareProperties`, skip `replaceBackgroundShorthand` for global keyword shorthands, and fix a pre-existing Map mutation-during-iteration bug by updating `parsedProperties` instead of `properties`.
- Mark `cssom-setProperty-shorthand.html` as passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@asamuzaK
Copy link
Copy Markdown
Contributor

LGTM

@domenic domenic merged commit 1e8a7ff into main Mar 19, 2026
9 checks passed
@domenic domenic deleted the border-global-keyword-fix branch March 19, 2026 23:55
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