Skip to content

Conversation

@philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 21, 2024

This PR fixes an issue where JS configuration theme properties with dots or slashes in them would not migrate correctly. E.g.:

import { type Config } from 'tailwindcss'

module.exports = {
  theme: {   
    width: {
      1.5: '0.375rem',
      '1/2': '50%',
    }
  }
}

This should convert to:

@theme {
  --width-1_5: 0.375rem;
  --width-1\/2: 50%;
}

Note: We will likely change the --width-1_5 key to --width-1\.5 in a follow-up PR.

Copy link
Member Author

philipp-spiess commented Oct 21, 2024

@philipp-spiess philipp-spiess marked this pull request as ready for review October 21, 2024 10:45
@philipp-spiess philipp-spiess requested a review from a team as a code owner October 21, 2024 10:45
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name branch from 06b6d11 to 19e512d Compare October 21, 2024 10:45
Copy link
Member

@adamwathan adamwathan left a comment

Choose a reason for hiding this comment

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

Should we just be using CSS.escape or whatever on all JS stuff when converting it to CSS? There’s tons of other characters someone could be using in their JS config that need to be escaped when converted to CSS as well, like percentage signs for example.

@philipp-spiess philipp-spiess marked this pull request as draft October 21, 2024 12:21
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name branch from 19e512d to ddcebfb Compare October 21, 2024 15:29
@philipp-spiess philipp-spiess changed the base branch from next to 10-21-escape_js_theme_configuration_keys October 21, 2024 15:29
@philipp-spiess philipp-spiess marked this pull request as ready for review October 21, 2024 15:29
@philipp-spiess philipp-spiess force-pushed the 10-21-escape_js_theme_configuration_keys branch from fb06b4c to 99072ca Compare October 21, 2024 16:06
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name branch from ddcebfb to e9c9f7e Compare October 21, 2024 16:07
@philipp-spiess philipp-spiess force-pushed the 10-21-escape_js_theme_configuration_keys branch from 99072ca to f99717b Compare October 22, 2024 11:34
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name branch from e9c9f7e to 47f75e8 Compare October 22, 2024 11:34
Copy link
Member Author

philipp-spiess commented Oct 22, 2024

Merge activity

  • Oct 22, 12:07 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 12:09 PM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 22, 12:30 PM EDT: The Graphite merge queue removed this pull request due to downstack failures on PR #14739.
  • Oct 22, 12:30 PM EDT: The Graphite merge queue removed this pull request due to downstack failures on PR #14739.
  • Oct 22, 12:38 PM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 22, 12:40 PM EDT: The Graphite merge queue removed this pull request due to downstack failures on PR #14739.
  • Oct 22, 1:07 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 1:07 PM EDT: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Oct 22, 1:07 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 3:46 PM EDT: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Oct 22, 3:48 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 3:48 PM EDT: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Oct 22, 3:49 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.

…grade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name
@RobinMalfait RobinMalfait changed the base branch from 10-21-escape_js_theme_configuration_keys to graphite-base/14736 October 22, 2024 16:56
Comment on lines 125 to 134
let property = keyPathToCssProperty([key[0]])
if (property !== null) {
css += ` --${escape(property)}-*: initial;\n`
}
}

css += ` --${keyPathToCssProperty(key)}: ${value};\n`
let property = keyPathToCssProperty(key)
if (property !== null) {
css += ` --${escape(property)}: ${value};\n`
}
Copy link
Member

Choose a reason for hiding this comment

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

It might be wise to prepend the -- before running escape here, because certain characters need to be escaped if they are the very first character but don't need to be escaped if they are not:

image

@adamwathan adamwathan merged commit 15ec670 into graphite-base/14736 Oct 22, 2024
2 checks passed
@adamwathan adamwathan deleted the 10-21-upgrade_migrate_js_theme_configuration_keys_with_dot_and_slash_in_the_property_name branch October 22, 2024 19:57
philipp-spiess added a commit that referenced this pull request Oct 23, 2024
…e property name (#14736)

This PR fixes an issue where JS configuration theme properties with dots
or slashes in them would not migrate correctly. E.g.:

```ts
import { type Config } from 'tailwindcss'

module.exports = {
  theme: {   
    width: {
      1.5: '0.375rem',
      '1/2': '50%',
    }
  }
}
```

This should convert to:

```css
@theme {
  --width-1_5: 0.375rem;
  --width-1\/2: 50%;
}
```

_Note: We will likely change the `--width-1_5` key to `--width-1\.5` in
a follow-up PR._

---------

Co-authored-by: Robin Malfait <[email protected]>
Co-authored-by: Adam Wathan <[email protected]>
Co-authored-by: Adam Wathan <[email protected]>
@philipp-spiess
Copy link
Member Author

Merged into next as 41decce

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.

5 participants