fix: resolve single box-shadow from runtime CSS variables#295
Open
YevheniiKotyrlo wants to merge 1 commit intonativewind:mainfrom
Open
fix: resolve single box-shadow from runtime CSS variables#295YevheniiKotyrlo wants to merge 1 commit intonativewind:mainfrom
YevheniiKotyrlo wants to merge 1 commit intonativewind:mainfrom
Conversation
When a CSS variable holding a single box-shadow value is resolved at runtime, the shorthand handler receives a flat array of tokens like [0, 4, 6, -1, "#000"]. The handler incorrectly iterates each primitive individually, none match any shadow pattern, and the result is an empty array. Detect flat vs nested arrays before entering the multi-shadow handler. A flat array is a single shadow's tokens that should be passed directly to the pattern handler. A nested array contains multiple shadows for the existing flatMap logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
box-shadowshorthand resolution when CSS variables are resolved at runtime (not inlined at compile time). Currently, a single shadow from a runtime variable producesboxShadow: []instead of the expected shadow object.Problem
When a CSS variable holding a single
box-shadowvalue is resolved at runtime, the shorthand handler receives a flat array of tokens like[0, 4, 6, -1, "#000"]. The handler incorrectly iterates each primitive individually — passing0,4,6, etc. to the pattern matcher one at a time. No single primitive matches any shadow pattern, so all returnundefinedand get filtered out.The runtime path is triggered when variables are:
:root+.darkfor theme switching)inlineVariables: false)The compile-time path (single-definition variables that get inlined) is not affected — lightningcss parses the full shadow value correctly.
Reproduction
Expected:
boxShadow: [{ offsetX: 0, offsetY: 4, blurRadius: 6, spreadDistance: -1, color: "#000" }]Actual:
boxShadow: []Solution
Detect whether the resolved args array is flat (single shadow) or nested (multiple shadows) before entering the multi-shadow handler:
[0, 4, 6, -1, "#000"]→ first element is a primitive → pass the entire array to the pattern handler as a single shadow[[0, 4, 6, -1, "#000"], [0, 1, 2, 0, "#333"]]→ first element is an array → use existingflatMaplogic for multiple shadowsThe existing multi-shadow path (nested arrays from comma-separated
box-shadowvalues) is unchanged.Verification
yarn typecheck— passyarn lint— passyarn build— passyarn test— 971 passed, 3 failed (pre-existing babel plugin tests), 22 skipped (pre-existing)Related