Skip to content

fix: recover shorthand CSS properties containing var() references#38

Draft
LuLaValva wants to merge 1 commit intomainfrom
fix/shorthand-var-css-properties
Draft

fix: recover shorthand CSS properties containing var() references#38
LuLaValva wants to merge 1 commit intomainfrom
fix/shorthand-var-css-properties

Conversation

@LuLaValva
Copy link
Copy Markdown
Member

I was playing with adding this to evo-web and ran into some issues.

When a CSS shorthand (e.g. border-radius) contains var() references, browsers list longhand names in style[i] but return empty strings for getPropertyValue() on each longhand. The previous rollup loop walked arbitrary dash segments instead of the CSS shorthand hierarchy, causing these properties to be silently dropped from snapshots.

Replace the rollup loop with a two-pass approach:

  1. First pass iterates style[i] as before, tracking longhands with empty values in a Set instead of attempting dash-stripping
  2. Second pass (only when empty longhands exist) parses style.cssText with a character-by-character parser that handles nested parentheses (e.g. var(--x, calc(100% - 20px))) to recover shorthand declarations

Also strips !important suffixes from cssText values since priority is handled separately via getPropertyPriority().

When a CSS shorthand (e.g. border-radius) contains var() references,
browsers list longhand names in style[i] but return empty strings for
getPropertyValue() on each longhand. The previous rollup loop walked
arbitrary dash segments instead of the CSS shorthand hierarchy, causing
these properties to be silently dropped from snapshots.

Replace the rollup loop with a two-pass approach:
1. First pass iterates style[i] as before, tracking longhands with
   empty values in a Set instead of attempting dash-stripping
2. Second pass (only when empty longhands exist) parses style.cssText
   with a character-by-character parser that handles nested parentheses
   (e.g. var(--x, calc(100% - 20px))) to recover shorthand declarations

Also strips !important suffixes from cssText values since priority is
handled separately via getPropertyPriority().
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.

1 participant