Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve root file detection #15048

Merged
merged 3 commits into from
Nov 19, 2024
Merged

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Nov 19, 2024

This PR fixes an issue where the Tailwind root file detection was wrong.

Whenever a CSS file contains any of the @tailwind directives or an @import to any of the Tailwind files, the file is considered a Tailwind root file.

If multiple CSS files are part of the same tree, then we make the nearest common parent the root file.

This root file will be the file where we add @config and/or inject other changes during the migration process.

However, if your folder structure looked like this:

/* index.css */
@import "./base.css";
@import "./typography.css";
@import "tailwindcss/components"; /* This makes index.css a root file */
@import "./utilities.css";

/* base.css */
@tailwind base; /* This makes base.css a root file */

/* utilities.css */
@tailwind utilities; /* This makes utilities.css a root file */

Then we computed that index.css nad base.css were considered root files even though they belong to the same tree (because base.css is imported by index.css).

This PR fixes that behaviour by essentially being less smart, and just checking again if any sheets are part of the same tree.

Test plan:

Added an integration test that covers this scenario and fails before the fix.

Also ran it on our tailwindcss.com codebase.

Before After
image image

(Yes, I know the migration still fails, but that's a different issue.)

Instead of trying to be smart, let's keep checking for common root files
among the common parents until we don't find common parents anymore.
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 19, 2024 23:00
@RobinMalfait RobinMalfait enabled auto-merge (squash) November 19, 2024 23:19
@RobinMalfait RobinMalfait merged commit f19afd9 into next Nov 19, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the fix/keep-looking-for-common-parents branch November 19, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants