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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- _Upgrade (experimental)_: Migrate prefixes for `.group` and `.peer` classes ([#15208](https://github.com/tailwindlabs/tailwindcss/pull/15208))

### Fixed

- Ensure any necessary vendor prefixes are generated for iOS Safari, Firefox, and Chrome ([#15166](https://github.com/tailwindlabs/tailwindcss/pull/15166))
Expand Down
6 changes: 6 additions & 0 deletions integrations/upgrade/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ test(
<div
class="!tw__flex sm:!tw__block tw__bg-gradient-to-t flex [color:red] group-[]:tw__flex"
></div>
<div
class="tw__group tw__group/foo tw__peer tw__peer/foo group-hover:tw__flex group-hover/foo:tw__flex peer-hover:tw__flex peer-hover/foo:tw__flex"
></div>
`,
'src/input.css': css`
@tailwind base;
Expand All @@ -208,6 +211,9 @@ test(
<div
class="tw:flex! tw:sm:block! tw:bg-linear-to-t flex tw:[color:red] tw:in-[.tw\\:group]:flex"
></div>
<div
class="tw:group tw:group/foo tw:peer tw:peer/foo tw:group-hover:flex tw:group-hover/foo:flex tw:peer-hover:flex tw:peer-hover/foo:flex"
></div>

--- ./src/input.css ---
@import 'tailwindcss' prefix(tw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('for projects with configured prefix', () => {

// Adds prefix to arbitrary candidates
['[color:red]', 'tw:[color:red]'],

// `.group` and `.peer` classes
['tw-group', 'tw:group'],
['tw-group/foo', 'tw:group/foo'],
['tw-peer', 'tw:peer'],
['tw-peer/foo', 'tw:peer/foo'],
])('%s => %s', async (candidate, result) => {
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss" prefix(tw);', {
base: __dirname,
Expand Down
8 changes: 8 additions & 0 deletions packages/@tailwindcss-upgrade/src/template/codemods/prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { segment } from '../../../../tailwindcss/src/utils/segment'
import { printCandidate } from '../candidates'

let seenDesignSystems = new WeakSet<DesignSystem>()

export function prefix(
designSystem: DesignSystem,
userConfig: Config,
rawCandidate: string,
): string {
if (!designSystem.theme.prefix) return rawCandidate

if (!seenDesignSystems.has(designSystem)) {
designSystem.utilities.functional('group', () => null)
designSystem.utilities.functional('peer', () => null)
seenDesignSystems.add(designSystem)
}

let v3Base = extractV3Base(designSystem, userConfig, rawCandidate)

if (!v3Base) return rawCandidate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ const LEGACY_CLASS_MAP = {
'outline-none': 'outline-hidden',
}

const SEEDED = new WeakSet<DesignSystem>()
let seenDesignSystems = new WeakSet<DesignSystem>()

export function simpleLegacyClasses(
designSystem: DesignSystem,
_userConfig: Config,
rawCandidate: string,
): string {
// Prepare design system with the unknown legacy classes
if (!SEEDED.has(designSystem)) {
if (!seenDesignSystems.has(designSystem)) {
for (let old in LEGACY_CLASS_MAP) {
designSystem.utilities.static(old, () => [])
}
SEEDED.add(designSystem)
seenDesignSystems.add(designSystem)
}

for (let candidate of designSystem.parseCandidate(rawCandidate)) {
Expand Down