[Grid] Fix Grid v1 spacing when using CSS variables #44663
Merged
+69
−34
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
Closes: #44662
Sadly, we went back and forth in regressions with #40224, #42574 and #44376.
The issue
This latest regression is caused because
-calc(...)
values are not valid, see https://codepen.io/diegoandai/pen/qEWboqp. The Grid is outputting-calc(...)
margin values whencssVariables: true
:The solution
This PR fixes it by replacing
-calc(...)
withcalc(-1 * calc(...))
. It also replaces-<pixelValue>px
withcalc(-1 * pixelValue)
as I don't think it's worth it adding the logic to differentiate between cases inside the Grid.Before: https://stackblitz.com/edit/react-ziw5rb?file=Demo.tsx,package.json
After: https://codesandbox.io/p/sandbox/pull-44663-after-jvt2tj
Post mortem
As a post-mortem of the multiple regressions, what I think enabled them was not having enough tests with each PR to cover the cases being fixed.
What I don't like about this fix is that it also changes the implementation for users who are not using CSS variables. Although the result should be the same, I hope there are no edge cases to my approach. If there are an ideas for how to fix this without changing the functionality for non-CSS variables users, I'll be happy to refactor the solution.