Fix infinite loop when using @variant inside @custom-variant that points to another @custom-variant#19633
Merged
RobinMalfait merged 5 commits intomainfrom Feb 2, 2026
Merged
Fix infinite loop when using @variant inside @custom-variant that points to another @custom-variant#19633RobinMalfait merged 5 commits intomainfrom
@variant inside @custom-variant that points to another @custom-variant#19633RobinMalfait merged 5 commits intomainfrom
Conversation
With a bit more info by introducing an additional selector
When handling `@custom-variants` we substitute the `@slot` with the incoming nodes. The issue is that the `nodes` might contain a `@slot` as well, but we don't want to keep replacing it with itself. The `@slot` that gets introduced is coming from _another_ `@custom-variant` so once we replace a `@slot`, we can stop traversing the new nodes.
Contributor
WalkthroughThis pull request addresses an infinite loop issue occurring when using 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
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.
This PR fixes an infinite loop when you use a
@variantinside of a@custom-variant, where the@variantused is another@custom-variant.The issue stems from the fact that a
@custom-variantcan use a@slotthat we have to replace with the proper AST nodes. However in this setup, the AST nodes will include a@slotnode as well, which causes us to replace the@slotagain, and so on, causing an infinite loop.The solution here is to replace the
@slotnodes and then skip walking the nodes that were just inserted. This does mean that we end up with a@slotnode in the final AST but that's not a real issue because that will get replaced later when handling the next@custom-variant.Test plan
Thanks @wongjn for your initial debugging help and providing a test case as well!
Fixes: #19618