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

Tailwind CSS v4 Selector Parsing Issue with Empty String Attribute #16660

Open
coderrshyam opened this issue Feb 19, 2025 · 2 comments
Open

Tailwind CSS v4 Selector Parsing Issue with Empty String Attribute #16660

coderrshyam opened this issue Feb 19, 2025 · 2 comments
Labels

Comments

@coderrshyam
Copy link

Tailwind CSS v4 Selector Parsing Issue with Empty String Attribute

Environment

  • Tailwind CSS Version: 4.0.7
  • Framework: Next.js 15.1.7
  • Node.js Version: 22.14.0
  • Browser: Chrome
  • Operating System: Windows

Reproduction

Repository: https://github.com/coderrshyam/next.js-hook-webpack-error

Steps to Reproduce:

  1. Clone the repository:
git clone https://github.com/coderrshyam/next.js-hook-webpack-error.git
cd next.js-hook-webpack-error
  1. Install dependencies:
pnpm install
  1. Attempt to build the project:
pnpm build

Issue Description:

When attempting to build a Next.js project with Tailwind CSS v4, an issue occurs with CSS selector parsing, specifically for selectors containing attribute selectors with empty string values.

The problematic selector: .prose code[data-theme*=" "]

Behavior in Tailwind CSS v3 (Working Correctly)

In Tailwind CSS v3, the selector is parsed correctly:

Parser {
  rule: '.prose code[data-theme*=" "]',
  options: { lossy: false, safe: false },
  position: 8,
  css: '.prose code[data-theme*=" "]',
  // ... other properties
}

Behavior in Tailwind CSS v4 (Incorrect)

In Tailwind CSS v4, the selector is not parsed correctly:

Parser {
  rule: '.prose code[data-theme*=\\]',
  options: { lossy: false, safe: false },
  position: 8,
  css: '.prose code[data-theme*=\\]', 
  // ... other properties
}

Expected Behavior

The parser in Tailwind CSS v4 should correctly handle the empty string in the attribute selector, similar to how it was handled in v3.

Actual Behavior

The parser in Tailwind CSS v4 seems to be escaping or misinterpreting the empty string in the attribute selector, leading to an incorrect parsing of the CSS rule.

Additional Notes

  • This issue specifically occurs during the build process of a Next.js project.
  • The problem appears to be isolated to cases where an attribute selector contains an empty string value.
@philipp-spiess
Copy link
Member

Hey! This seems like an issue in the upstream handling of the CSS file, I can reproduce this without Tailwind CSS. The reason is that we minify the selector you mentioned to something like this (in it's most minimal form):

[data-attr=\ ] {
  color: red;
}

This works in the browsers but will trip up Next.js/webpack right now.

I created an upstream bug report for this: vercel/next.js#76269

@coderrshyam
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants