-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Do not migrate legacy classes with custom values #14976
Conversation
Implemented the proper solution to compare values to ensure the migration is safe. |
f81d2b3
to
0a64140
Compare
packages/@tailwindcss-upgrade/src/template/codemods/legacy-classes.ts
Outdated
Show resolved
Hide resolved
// Prepare design system with the unknown legacy classes | ||
if (!SEEDED.has(designSystem)) { | ||
for (let old in LEGACY_CLASS_MAP) { | ||
designSystem.utilities.static(old, () => []) | ||
} | ||
SEEDED.add(designSystem) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment, the reason we do need this is to make the migration easier by registering the shadow-sm
(or all old classes) as a static utility so that the candidate.root
is the actual class.
If we don't do this, then we have to deal with all kinds of candidate types (which might be fine). But that also means looking at the value and migrating those.
At the end of the day it's easier to migrate:
[
{
"kind": "static",
"root": "shadow-sm",
"variants": [],
"important": false,
"raw": "shadow-sm"
},
]
Compared to this:
[
{
"kind": "functional",
"root": "shadow",
"modifier": null,
"value": {
"kind": "named",
"value": "sm",
"fraction": null
},
"variants": [],
"important": false,
"raw": "shadow-sm"
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this might cause issues downstream though since the designSystem
is passed through the whole migration pipeline and now it has shadow-sm
added everywhere wrongly, just for this migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c63f01b
to
9f5a87a
Compare
622c4b6
to
4bf1b7a
Compare
This allows us to commit the "before" state, once you are debugging you can see the after state as a diff.
The simple legacy classes migration isn't as simple anymore now that we have to check the design system. Split it into 2 separate migrations instead.
This PR makes sure that migrations from suffix-less candidates (e.g.: `rounded`, `blur`, `shadow`) are safe to be migrated. In some code snippets that's not always the case. Given the following code snippet: ```tsx type Star = [ x: number, y: number, dim?: boolean, blur?: boolean, rounded?: boolean, shadow?: boolean, ] function Star({ point: [cx, cy, dim, blur, rounded, shadow] }: { point: Star }) { return <svg class="rounded shadow blur" filter={blur ? 'url(…)' : undefined} /> } ``` Without this change, it would result in: ```tsx type Star = [ x: number, y: number, dim?: boolean, blur-sm?: boolean, rounded-sm?: boolean, shadow-sm?: boolean, ] function Star({ point: [cx, cy, dim, blur-sm, rounded-sm, shadow-sm] }: { point: Star }) { return <svg class="rounded-sm shadow-sm blur-sm" filter={blur-sm ? 'url(…)' : undefined} /> } ``` But with this change, it results in: ```tsx type Star = [ x: number, y: number, dim?: boolean, blur?: boolean, rounded?: boolean, shadow?: boolean, ] function Star({ point: [cx, cy, dim, blur, rounded, shadow] }: { point: Star }) { return <svg class="rounded-sm shadow-sm blur-sm" filter={blur ? 'url(…)' : undefined} /> } ``` Notice how the classes inside the `class` attribute _are_ converted, but the ones in the types or as part of the JavaScript code (e.g.: `filter={blur ? 'url(…)' : undefined}`) are not. --------- Co-authored-by: Philipp Spiess <[email protected]>
Co-authored-by: Philipp Spiess <[email protected]>
Instead of creating an ad-hoc static utility for the candidate, we simplify the candidate to it's base form, then perform the change and then go back. E.g.: 1. Incoming string of `hover:blur!` 2. Is turned into the candidate AST for `hover:blur!` 3. Is simplified such that variants and important is stripped 4. Is printed as a string `blur` 5. Find replacement `blur-sm` 6. Parse into candidate AST 7. Re-apply the variants and important 8. Stringified `hover:blur-sm!`
4bf1b7a
to
69280d2
Compare
This PR fixes an issue where we migrated classes such as
rounded
torounded-sm
(see: #14875)However, if you override the values in your
tailwind.config.js
file, then the migration might not be correct.This PR makes sure to only migrate the classes if you haven't overridden the values in your
tailwind.config.js
file.