Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve style invalidation performance of `group-*` and `peer-*` variants ([#20513](https://github.com/tailwindlabs/tailwindcss/pull/20513))
- Ensure cached compilers don't keep `loadModule` and `loadStylesheet` callbacks alive after compilation ([#20531](https://github.com/tailwindlabs/tailwindcss/pull/20531))
- Canonicalization: keep the `&` when moving a pseudo-element into `*` or `**` (e.g. `[&_::before]:flex` → `**:[&::before]:flex`) ([#20550](https://github.com/tailwindlabs/tailwindcss/pull/20550))
- Fix `Set.prototype.intersection` polyfill in `canonicalizeCandidates(…)` on Node.js < 22, which returned the first set instead of the intersection ([#20562](https://github.com/tailwindlabs/tailwindcss/pull/20562))

## [4.3.3] - 2026-07-16

Expand Down
43 changes: 43 additions & 0 deletions packages/tailwindcss/src/canonicalize-candidates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'node:fs'
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { __unstable__loadDesignSystem } from '.'
import { intersection } from './canonicalize-candidates'
import { cartesian } from './cartesian'
import type { CanonicalizeOptions } from './intellisense'
import plugin from './plugin'
Expand Down Expand Up @@ -1666,3 +1667,45 @@ describe('regressions', () => {
).toEqual(['text-foreground/60', 'text-default-soft-hover'])
})
})

describe('intersection', () => {
// Shadow `Set.prototype.intersection` so that the polyfill is used, even on
// Node.js versions that have a native implementation.
function withoutNative<T>(set: Set<T>): Set<T> {
return Object.assign(set, { intersection: undefined })
}

test('polyfill keeps only the items that are in both sets', () => {
let a = withoutNative(new Set([1, 2, 3, 4]))
let b = new Set([3, 4, 5, 6])

expect(intersection(a, b)).toEqual(new Set([3, 4]))
expect(intersection(withoutNative(new Set(b)), a)).toEqual(new Set([3, 4]))
})

test('polyfill returns an empty set when the sets are disjoint', () => {
expect(intersection(withoutNative(new Set([1, 2])), new Set([3, 4]))).toEqual(new Set())
})

test('polyfill returns an empty set when one of the sets is empty', () => {
expect(intersection(withoutNative(new Set<number>()), new Set([1]))).toEqual(new Set())
expect(intersection(withoutNative(new Set([1])), new Set<number>())).toEqual(new Set())
})

test('polyfill does not mutate the input sets', () => {
let a = withoutNative(new Set([1, 2, 3]))
let b = new Set([2, 3, 4])

intersection(a, b)

expect(a).toEqual(new Set([1, 2, 3]))
expect(b).toEqual(new Set([2, 3, 4]))
})

test('native and polyfill implementations agree', () => {
let a = new Set(['a', 'b', 'c', 'd'])
let b = new Set(['b', 'd', 'e'])

expect(intersection(withoutNative(new Set(a)), b)).toEqual(intersection(a, b))
})
})
10 changes: 5 additions & 5 deletions packages/tailwindcss/src/canonicalize-candidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3055,17 +3055,17 @@ function* combinations<T>(arr: T[]): Generator<T[]> {
}
}

function intersection<T>(a: Set<T>, b: Set<T>): Set<T> {
export function intersection<T>(a: Set<T>, b: Set<T>): Set<T> {
// @ts-expect-error Set.prototype.intersection is only available in Node.js v22+
if (typeof a.intersection === 'function') return a.intersection(b)

// Polyfill for environments that do not support Set.prototype.intersection yet
if (a.size === 0 || b.size === 0) return new Set<T>()

let result = new Set<T>(a)
for (let item of b) {
if (!result.has(item)) {
result.delete(item)
let result = new Set<T>()
for (let item of a) {
if (b.has(item)) {
result.add(item)
}
}

Expand Down