Detect ambiguity in arbitrary values #5634
Merged
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.
If you use arbitrary values for the
bgutilities, then it could happen that you introduce some ambiguity. When you use arbitrary values, then we can detect the type of the input. For example#ff00ffis a color,20%is a percentage and so on.The value here would be parsed as
length. However, we have 2 plugins (backgroundSizeandbackgroundPosition) that can handle this plugin. Before this plugin this would have generated:This will also probably be squashed together like this:
This will not be the desired result, instead you can use
typehintsto explicitly tell what the value means. In this case, thebackgroundPositionplugin implements apositiontype. This means that we can explicit here:This will now generate the correct results with a unique selector:
That said, this PR will be able to detect the very first case
bg-[200px_100px]and not generate css for that at all, instead it will show you a warning in the console:Note: There is a high chance that the warning will be changed/simplified, but at least we can detect it!