镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Prevent modifying CSS variables in plugins - #16103

Merged
RobinMalfait merged 5 commits into
tailwindlabs:mainfrom
siriwatknp:fix/plugin-css-variables2
Jan 31, 2025
Merged

RobinMalfait merged 5 commits into
tailwindlabs:mainfrom
siriwatknp:fix/plugin-css-variables2

Conversation

@siriwatknp

Copy link
Copy Markdown
Contributor

closes #16100

@siriwatknp
siriwatknp requested a review from a team as a code owner January 31, 2025 09:20
@siriwatknp siriwatknp changed the title prevent modifying CSS variables in plugins Prevent modifying CSS variables in plugins Jan 31, 2025

@philipp-spiess philipp-spiess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes perfect sense, thanks for the contribution! Got some nit inline. Happy to take over and bring it to the finish line though. We'll also want to add a change log entry for this like Ensure CSS variables declared in JavaScript plugins don't have their casing changed or so 🙂

// Convert camelCase to kebab-case:
// https://github.com/postcss/postcss-js/blob/b3db658b932b42f6ac14ca0b1d50f50c4569805b/parser.js#L30-L35
name = name.replace(/([A-Z])/g, '-$1').toLowerCase()
if (!name.startsWith('--')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have this exact same check three lines above, perhaps we can move it outside the if into a variable so we only need to do this computation once? 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another option is to refactor this a little bit:

      if (!name.startsWith('--')) {
        if (value === '@slot') {
          ast.push(rule(name, [atRule('@slot')]))
          continue
        }

        // Convert camelCase to kebab-case:
        // https://github.com/postcss/postcss-js/blob/b3db658b932b42f6ac14ca0b1d50f50c4569805b/parser.js#L30-L35
        name = name.replace(/([A-Z])/g, '-$1').toLowerCase()
      }

      ast.push(decl(name, String(value)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Went ahead and pushed this so that we can get it merged today 👍

@RobinMalfait
RobinMalfait force-pushed the fix/plugin-css-variables2 branch from 5a25e87 to 3a4ba87 Compare January 31, 2025 11:12
@RobinMalfait
RobinMalfait force-pushed the fix/plugin-css-variables2 branch from 3a4ba87 to 2006445 Compare January 31, 2025 11:22
Comment thread CHANGELOG.md Outdated
- Refactor gradient implementation to work around [prettier/prettier#17058](https://github.com/prettier/prettier/issues/17058) ([#16072](https://github.com/tailwindlabs/tailwindcss/pull/16072))
- Vite: Ensure hot-reloading works with SolidStart setups ([#16052](https://github.com/tailwindlabs/tailwindcss/pull/16052))
- Vite: Fix a crash when starting the development server in SolidStart setups ([#16052](https://github.com/tailwindlabs/tailwindcss/pull/16052))
- Do not camelCase CSS custom properties ([#16103](https://github.com/tailwindlabs/tailwindcss/pull/16103))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Do not camelCase CSS custom properties ([#16103](https://github.com/tailwindlabs/tailwindcss/pull/16103))
- Do not camelCase CSS custom properties added by JavaScript plugins ([#16103](https://github.com/tailwindlabs/tailwindcss/pull/16103))

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Co-authored-by: Philipp Spiess <hello@philippspiess.com>
@siriwatknp

Copy link
Copy Markdown
Contributor Author

Makes perfect sense, thanks for the contribution! Got some nit inline. Happy to take over and bring it to the finish line though. We'll also want to add a change log entry for this like Ensure CSS variables declared in JavaScript plugins don't have their casing changed or so 🙂

Thanks for the fast response!

@RobinMalfait
RobinMalfait enabled auto-merge (squash) January 31, 2025 11:44
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.

CSS variables created by plugins are modified

3 participants