-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure multiple --value(…)
or --modifier(…)
calls don't delete subsequent declarations
#17273
Conversation
packages/tailwindcss/src/ast.ts
Outdated
if (replacedNode) { | ||
throw new Error('Cannot replace a node more than once') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also silently ignore this but then we are just hiding a bug.
Maybe we could write a better error message here that this is a Tailwind internal bug? /cc @adamwathan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just not throw here? Is there something the user can do that triggers this or does it only signal a bug in Tailwind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing the user can do and signals a bug in Tailwind for sure because we are the only ones using this API.
Only issue about silently ignoring is that we wouldn't immediately know about an issue. And worse, maybe some APIs start relying on this odd behavior.
If we had thrown here than the bug you ran into would be obvious but would also break everything 🫣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping in a suggestion here:
Cannot replace a node more than once. This is a bug in Tailwind CSS. Please open an issue with a reproduction at https://github.com/tailwindlabs/tailwindcss/issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there are probably a million places in the code where we could add conditionals like this if we really wanted right? Feels weird to me that this would be the first time we ever introduced a throw to tell us we made a mistake. I don’t think we’ve ever done this any other time we fixed a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah makes sense. I silently bailed so at least we are not mutating other AST nodes.
Other solution is to silently ignore, but that feels even more buggy.
8ed9a80
to
9501584
Compare
This PR fixes a bug in the handling of
@utility
. Essentially if you had a declaration where you used a--modifier(…)
and a--value(…)
and both caused the declaration to be removed, the declaration after the current one would be removed as well.This happened because 2 reasons:
--modifier(…)
, we didn't stop the walk and kept going.replaceWith(…)
code allows you to call the function multiple times but immediately mutates the AST. This means that if you call it multiple times that you are potentially removing / updating nodes followed by the current one.E.g.:
If this is used as
mask-r-10%
, then the first definition of--mask-right
is kept, but the second definition of--mask-right
is deleted because both--modifier(integer)
and--value(integer)
do not result in a valid value.However, the
mask-image
declaration was also removed because thereplaceWith(…)
function was called twice. Once for--modifier(integer)
and once for--value(integer)
.Test plan
replaceWith(…)
multiple times.