Fix "Cannot read properties of undefined" crash on malformed arbitrary value #18133
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.
This PR fixes a crash when an arbitrary value was malformed and crashed the build.
If you have a utility like
[--btn-border:var(--color-maroon)/90)]
which is malformed, it will crash the build. It might not be easy to spot but the easy is the additional)
after the90
.The reason this crashes is because we parse the value
var(--color-maroon)/90)
and when we see)
we assume it's the end of a "function" which also assumes it was preceded by a(
. This is not the case and we crash.This PR fixes that by not assuming the parsed object is available and uses
?
to be safe and only accessnodes
if it's available.I'm actually not 100% sure what the best solution is in this scenario because these candidates could (and will) be returned from Oxide so even if we throw a more descriptive error, it will still crash the build and you might not even have control over the candidate.
This candidate will now eventually generate the following CSS:
Which still looks odd, but even Lightning CSS doesn't throw an error in this case (because it's a CSS variable definition), so I think it's the best we can do. If you open your devtools you will see the weird values, so it's still debug-able.
Fixes: #17064
Test plan
Manually tested the candidate that crashed it, and after the change generated the above CSS. Then used it in JSFiddle to proof it's fixed now. https://jsfiddle.net/z850ykew/
Couldn't use Tailwind Play because the candidate will cause a crash there as well 😅