Commit 884f02c
authored
Fix "Cannot read properties of undefined" crash on malformed arbitrary value (#18133)
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 the `90`.
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 access `nodes` 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:
```css
.\[--btn-border\:var\(--color-maroon\)\/90\)\] {
--btn-border: var(--color-maroon) / ;
}
```
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.
<img width="359" alt="image"
src="https://github.com/user-attachments/assets/2eb48662-64de-4417-a2da-1577bf9075b5"
/>
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 😅1 parent 9cb3899 commit 884f02c
File tree
4 files changed
+35
-17
lines changed- packages/tailwindcss/src
4 files changed
+35
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4305 | 4305 | | |
4306 | 4306 | | |
4307 | 4307 | | |
4308 | | - | |
| 4308 | + | |
4309 | 4309 | | |
4310 | 4310 | | |
| 4311 | + | |
4311 | 4312 | | |
4312 | | - | |
4313 | 4313 | | |
4314 | 4314 | | |
4315 | 4315 | | |
| |||
4355 | 4355 | | |
4356 | 4356 | | |
4357 | 4357 | | |
4358 | | - | |
| 4358 | + | |
4359 | 4359 | | |
4360 | 4360 | | |
| 4361 | + | |
4361 | 4362 | | |
4362 | | - | |
4363 | 4363 | | |
4364 | 4364 | | |
4365 | 4365 | | |
| |||
4442 | 4442 | | |
4443 | 4443 | | |
4444 | 4444 | | |
4445 | | - | |
| 4445 | + | |
4446 | 4446 | | |
4447 | 4447 | | |
4448 | 4448 | | |
4449 | 4449 | | |
4450 | 4450 | | |
4451 | 4451 | | |
4452 | 4452 | | |
4453 | | - | |
| 4453 | + | |
4454 | 4454 | | |
4455 | 4455 | | |
4456 | 4456 | | |
| |||
4474 | 4474 | | |
4475 | 4475 | | |
4476 | 4476 | | |
4477 | | - | |
| 4477 | + | |
4478 | 4478 | | |
4479 | 4479 | | |
4480 | 4480 | | |
| 4481 | + | |
4481 | 4482 | | |
4482 | | - | |
4483 | 4483 | | |
4484 | 4484 | | |
4485 | 4485 | | |
4486 | 4486 | | |
4487 | 4487 | | |
4488 | 4488 | | |
4489 | 4489 | | |
| 4490 | + | |
4490 | 4491 | | |
4491 | | - | |
4492 | 4492 | | |
4493 | 4493 | | |
4494 | 4494 | | |
4495 | 4495 | | |
4496 | 4496 | | |
4497 | 4497 | | |
4498 | 4498 | | |
| 4499 | + | |
4499 | 4500 | | |
4500 | | - | |
4501 | 4501 | | |
4502 | 4502 | | |
4503 | 4503 | | |
| |||
5519 | 5519 | | |
5520 | 5520 | | |
5521 | 5521 | | |
5522 | | - | |
| 5522 | + | |
5523 | 5523 | | |
5524 | 5524 | | |
5525 | 5525 | | |
| |||
5530 | 5530 | | |
5531 | 5531 | | |
5532 | 5532 | | |
5533 | | - | |
| 5533 | + | |
5534 | 5534 | | |
5535 | 5535 | | |
5536 | 5536 | | |
| |||
5551 | 5551 | | |
5552 | 5552 | | |
5553 | 5553 | | |
5554 | | - | |
| 5554 | + | |
5555 | 5555 | | |
5556 | 5556 | | |
5557 | 5557 | | |
| |||
5562 | 5562 | | |
5563 | 5563 | | |
5564 | 5564 | | |
5565 | | - | |
| 5565 | + | |
5566 | 5566 | | |
5567 | 5567 | | |
5568 | 5568 | | |
| |||
5573 | 5573 | | |
5574 | 5574 | | |
5575 | 5575 | | |
5576 | | - | |
| 5576 | + | |
5577 | 5577 | | |
5578 | 5578 | | |
5579 | 5579 | | |
| |||
5605 | 5605 | | |
5606 | 5606 | | |
5607 | 5607 | | |
5608 | | - | |
| 5608 | + | |
5609 | 5609 | | |
5610 | 5610 | | |
| 5611 | + | |
5611 | 5612 | | |
5612 | 5613 | | |
5613 | 5614 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
168 | 184 | | |
169 | 185 | | |
170 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
| 305 | + | |
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| |||
0 commit comments