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

Do not migrate legacy classes with custom values #14976

Merged
merged 12 commits into from
Nov 14, 2024

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where we migrated classes such as rounded to rounded-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.

@RobinMalfait
Copy link
Member Author

RobinMalfait commented Nov 12, 2024

Initial implementation: just check whether you have theme[themekey] or theme.extend[themekey] defined. An improvement to this is actually comparing the value from the "before" state to the value of the "after" state. if those are the same, then we can safely migrate the value.

Implemented the proper solution to compare values to ensure the migration is safe.

@RobinMalfait RobinMalfait force-pushed the feat/migrate-shadow-if-default branch 3 times, most recently from f81d2b3 to 0a64140 Compare November 12, 2024 15:40
integrations/utils.ts Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@RobinMalfait RobinMalfait marked this pull request as ready for review November 12, 2024 15:40
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 12, 2024 15:40
Comment on lines 56 to 98
// 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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore

Copy link
Member Author

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"
  }
]

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had an initial fix for this: d644a3f

Then improved it further: 4bf1b7a

@RobinMalfait RobinMalfait force-pushed the feat/migrate-shadow-if-default branch 3 times, most recently from c63f01b to 9f5a87a Compare November 13, 2024 15:24
@RobinMalfait RobinMalfait marked this pull request as draft November 13, 2024 15:44
@RobinMalfait RobinMalfait force-pushed the feat/migrate-shadow-if-default branch from 622c4b6 to 4bf1b7a Compare November 13, 2024 16:55
@RobinMalfait RobinMalfait marked this pull request as ready for review November 13, 2024 16:55
RobinMalfait and others added 12 commits November 14, 2024 08:17
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!`
@RobinMalfait RobinMalfait force-pushed the feat/migrate-shadow-if-default branch from 4bf1b7a to 69280d2 Compare November 14, 2024 07:17
@RobinMalfait RobinMalfait merged commit 49484f0 into next Nov 14, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the feat/migrate-shadow-if-default branch November 14, 2024 10:31
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