Skip to content

Commit dbc8023

Browse files
authored
Do not sort and format stylesheets that didn't change (#17824)
This PR improves the upgrade tooling at tiny bit to make sure that as long as we didn't change any of the stylesheets, that we also don't sort internal nodes and/or format the stylesheet at all. This is important in case the Prettier rules are different or if a totally different formatter is used. Essentially, if we didn't have to change the stylesheets because of a migration, we don't want to change it due to a formatter either.
1 parent d3846a4 commit dbc8023

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- PostCSS: Ensure that errors in stylesheet dependencies are recoverable ([#17754](https://github.com/tailwindlabs/tailwindcss/pull/17754))
2323
- Upgrade: Correctly print variants starting with `@` ([#17814](https://github.com/tailwindlabs/tailwindcss/pull/17814))
2424
- Skip `color-mix(…)` when opacity is `100%` ([#17815](https://github.com/tailwindlabs/tailwindcss/pull/17815))
25+
- Upgrade: Don't format stylesheets when nothing changed ([#17824](https://github.com/tailwindlabs/tailwindcss/pull/17824))
2526

2627
## [4.1.4] - 2025-04-14
2728

integrations/upgrade/index.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,6 @@ test(
12661266
12671267
--- ./src/c.1.css ---
12681268
@import './c.2.css' layer(utilities);
1269-
12701269
.baz-from-c {
12711270
color: green;
12721271
}

packages/@tailwindcss-upgrade/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async function run() {
9090
let stylesheets = loadResults
9191
.filter((result) => result.status === 'fulfilled')
9292
.map((result) => result.value)
93+
let originals = new Map(stylesheets.map((sheet) => [sheet, sheet.root.toString()]))
9394

9495
// Analyze the stylesheets
9596
try {
@@ -213,6 +214,7 @@ async function run() {
213214

214215
// Format nodes
215216
for (let sheet of stylesheets) {
217+
if (originals.get(sheet) === sheet.root.toString()) continue
216218
await postcss([sortBuckets(), formatNodes()]).process(sheet.root!, { from: sheet.file! })
217219
}
218220

0 commit comments

Comments
 (0)