Fix bug with nested @apply rules in utility classes (#17924)#17925
Merged
philipp-spiess merged 1 commit intomainfrom May 8, 2025
Merged
Fix bug with nested @apply rules in utility classes (#17924)#17925philipp-spiess merged 1 commit intomainfrom
philipp-spiess merged 1 commit intomainfrom
Conversation
## Bug When one utility applied another utility that contained pseudo-selectors (like :hover, :disabled), the pseudo-selectors were not properly carried through the dependency chain. This was because we were only tracking dependencies on the immediate parent rather than all parents in the path. ## Fix - Modified the dependency resolution to track dependencies through the entire parent path - Rewrote the node replacement logic to use the more robust walk() function - These changes ensure pseudo-selectors are properly preserved when utilities apply other utilities ## Test Plan - Run `vitest run packages/tailwindcss/src/index.test.ts` to verify the new test case passes - The test case verifies that when utility 'test2' applies utility 'test' with hover/disabled states, all pseudo-selectors are correctly preserved in the output CSS
9a1305a to
5e004e7
Compare
RobinMalfait
approved these changes
May 8, 2025
Comment on lines
+69
to
+74
| // Mark every parent in the path as having a dependency to that utility. | ||
| for (let parent of path) { | ||
| if (parent === node) continue | ||
| if (!parents.has(parent)) continue | ||
| dependencies.get(parent).add(dependency) | ||
| } |
Member
There was a problem hiding this comment.
Ah interesting, I knew we were performing a topological sort already so was confused why this didn't work.
But this makes sense, and tracking the full path also makes sense.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #17924
When an
@applypointed to utility that nested usages of@apply, these nested usages were not properly carried through the dependency chain. This was because we were only tracking dependencies on the immediate parent rather than all parents.To fix this, this PR:
walk(…)for the node replacement logic so that all nested@applyusages are also resolved (as these are now tracked in the dependency list anywaysTest Plan