tailwindcss/packages
Robin Malfait df96ea5eba
Fix infinite loop when using @variant inside @custom-variant that points to another @custom-variant (#19633)
This PR fixes an infinite loop when you use a `@variant` inside of a
`@custom-variant`, where the `@variant` used is another
`@custom-variant`.

The issue stems from the fact that a `@custom-variant` can use a `@slot`
that we have to replace with the proper AST nodes. However in this
setup, the AST nodes will include a `@slot` node as well, which causes
us to replace the `@slot` again, and so on, causing an infinite loop.

```css
@custom-variant a {
  @slot;
}

@custom-variant b {
  @variant a {
    @slot;
  }
}
```

The solution here is to replace the `@slot` nodes and then skip walking
the nodes that were just inserted. This does mean that we end up with a
`@slot` node 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

1. Existing tests still pass
2. Added a regression test to ensure that the infinite loop does not
happen anymore
3. Added additional tests to ensure that the behavior is correct

Thanks @wongjn for your initial debugging help and providing a test case
as well!

Fixes: #19618
2026-02-02 14:42:31 +01:00
..
@tailwindcss-browser Release v4.1.18 (#19431) 2025-12-11 10:55:25 -05:00
@tailwindcss-cli Update enhanced-resolve 5.18.3 → 5.18.4 (patch) (#19462) 2025-12-18 15:03:51 -05:00
@tailwindcss-node Update enhanced-resolve 5.18.3 → 5.18.4 (patch) (#19462) 2025-12-18 15:03:51 -05:00
@tailwindcss-postcss Add @tailwindcss/webpack loader for Tailwind CSS v4 (#19610) 2026-01-29 14:16:31 +00:00
@tailwindcss-standalone Update @types/bun 1.3.3 → 1.3.5 (patch) (#19491) 2025-12-25 18:22:13 -05:00
@tailwindcss-upgrade Fix typo in comment (#19493) 2025-12-27 11:56:29 -05:00
@tailwindcss-vite [tailwindcss-vite] Add Register dependency messages logline (#19611) 2026-01-29 14:17:50 +00:00
@tailwindcss-webpack Add @tailwindcss/webpack loader for Tailwind CSS v4 (#19610) 2026-01-29 14:16:31 +00:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Fix infinite loop when using @variant inside @custom-variant that points to another @custom-variant (#19633) 2026-02-02 14:42:31 +01:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00