Skip to content

Add Vite polyfills option#20036

Open
lubomirblazekcz wants to merge 1 commit into
tailwindlabs:mainfrom
lubomirblazekcz:vite-polyfills-option
Open

Add Vite polyfills option#20036
lubomirblazekcz wants to merge 1 commit into
tailwindlabs:mainfrom
lubomirblazekcz:vite-polyfills-option

Conversation

@lubomirblazekcz
Copy link
Copy Markdown
Contributor

@lubomirblazekcz lubomirblazekcz commented May 11, 2026

Summary

Closes #20035, #20038

Test plan

Added integrations tests

@lubomirblazekcz lubomirblazekcz requested a review from a team as a code owner May 11, 2026 07:41
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

Review Change Stack

Walkthrough

This PR adds a polyfills option to the Tailwind Vite plugin configuration, allowing users to control which CSS polyfills are emitted. The option is threaded from the PluginOptions interface through createRoot into the Root instance, where it is used during CSS compilation. For CSS Modules, the Polyfills.AtProperty flag is conditionally masked to prevent Vite from treating global rules as impure. The change includes updated documentation and a test case verifying the feature works correctly.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a new polyfills option to the Vite plugin configuration.
Linked Issues check ✅ Passed The PR successfully implements the requested polyfills option for the Vite plugin, allowing users to configure which polyfills are emitted, addressing all requirements in #20035.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue: exposing a polyfills option, updating documentation, and adding test coverage with no extraneous modifications.
Description check ✅ Passed The PR description references closed issues and mentions added integration tests, which aligns with the changeset that adds a polyfills option to the Vite plugin and includes test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/`@tailwindcss-vite/README.md:
- Line 80: Update the README paragraph about the polyfills option to clarify
that while Tailwind's default is to emit all supported CSS polyfills, CSS
Modules intentionally mask the AtProperty polyfill; mention that the `polyfills`
option controls emission but that `AtProperty` will be omitted when using CSS
Modules unless explicitly enabled, referencing the `polyfills` option and the
`AtProperty` polyfill name so readers can find the relevant behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ba356aa-0fca-455e-a068-f5eb916f3e45

📥 Commits

Reviewing files that changed from the base of the PR and between f9216b2 and 37ba9ad.

📒 Files selected for processing (3)
  • integrations/vite/index.test.ts
  • packages/@tailwindcss-vite/README.md
  • packages/@tailwindcss-vite/src/index.ts


## Controlling Tailwind polyfills

By default, Tailwind emits all supported CSS polyfills. You can customize this behavior using the `polyfills` option:
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify default behavior for CSS Modules in this section.

The “emits all supported CSS polyfills” sentence is not fully accurate for CSS Modules, where AtProperty is intentionally masked. A short note here would prevent confusion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/`@tailwindcss-vite/README.md at line 80, Update the README paragraph
about the polyfills option to clarify that while Tailwind's default is to emit
all supported CSS polyfills, CSS Modules intentionally mask the AtProperty
polyfill; mention that the `polyfills` option controls emission but that
`AtProperty` will be omitted when using CSS Modules unless explicitly enabled,
referencing the `polyfills` option and the `AtProperty` polyfill name so readers
can find the relevant behavior.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 11, 2026

Confidence Score: 4/5

The feature is additive and defaults to the existing behavior, so existing users are unaffected. The CSS-module guard correctly mirrors logic already in the webpack and PostCSS plugins.

The core logic is correct and safe to merge. The main gaps are a missing test for the CSS-module AtProperty-stripping branch and incomplete README documentation for bitflag composition — both non-blocking quality concerns.

The CSS-module branch in packages/@tailwindcss-vite/src/index.ts (lines 513–515) and the integration test file would benefit from an additional test case.

Reviews (1): Last reviewed commit: "Add Vite polyfills option" | Re-trigger Greptile

Comment on lines +513 to +515
polyfills: inputPath.endsWith('.module.css')
? this.polyfills & ~Polyfills.AtProperty
: this.polyfills,
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.

P2 CSS module polyfill stripping is untested

The new branch that strips Polyfills.AtProperty for .module.css files is not covered by any integration test. The parallel webpack and postcss plugins have the same logic already, and the comment explains why it's necessary, but without a test exercising a .module.css file with the vite plugin the guard could be silently removed or regressed. A test that builds a .module.css input and asserts @layer properties is absent would close this gap.

Comment on lines +77 to +93

## Controlling Tailwind polyfills

By default, Tailwind emits all supported CSS polyfills. You can customize this behavior using the `polyfills` option:

```js
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
import { Polyfills } from 'tailwindcss'

export default defineConfig({
plugins: [
tailwindcss({
// Disable all Tailwind polyfills
polyfills: Polyfills.None,
}),
],
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.

P2 Only Polyfills.None is shown; bitwise composition is undiscoverable

The README only demonstrates Polyfills.None. Because Polyfills is a bitflags enum (with AtProperty, ColorMix, and All), users who want to selectively disable just one polyfill (e.g., keep ColorMix but drop AtProperty) have no hint that they can pass Polyfills.ColorMix or Polyfills.AtProperty directly. A brief note or additional example showing per-flag control would make the API more discoverable.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Add support for polyfill configuration in Vite plugin

1 participant