Open saadeghi opened 4 days ago
This comes from our attribute escaping, because &
means the beginning of HTML entities. I'm not exactly sure if HTML is smart enough to detect if it's actually a real entity, and leaves it alone otherwise.
It is:
document.body.innerHTML = `<div class="&"></div>`;
document.querySelector('div').className; // '&'
document.body.innerHTML = `<div class="!"></div>`;
document.querySelector('div').className; // '!'
So — reluctantly — our escaping logic needs to get smart enough to handle this edge case.
I think you should move your tailwind vite plugin before sveltekit in your vite config
If I put the tailwind plugin before the sveltekit plugin, as suggested by @paoloricciuti , this works. Is there any reason you can't do that?
@paoloricciuti @dummdidumm Changing the order like plugins: [tailwindcss(), sveltekit()],
does not fix the issue.
Please provide an updated reproduction then - the given one causes no such error when changing the order.
Describe the bug
@tailwindcss/vite@alpha
gives Vite error if[&_div]:flex
class name andurl()
from a Tailwind plugin exists in app together.✅ Having a Tailwind plugin like this works as expected
✅ An arbitrary class name like
[&_div]:flex
works as expected.❌ But having both in the same project using
@tailwindcss/vite@4.0.0-alpha.30
causes Vite error:✅ This wasn't an issue in Tailwind CSS 3 or in Svelte 4 ✅ The issue doesn't happen with
@tailwindcss/cli@4.0.0-alpha.30
It was really hard to debug for me because Vite just says
Unknown word
. No more details. After days I found that arbitrary class names with[]
and&
cause the issue if there's a plugin includingurl()
with encoded image in it.additional info from @thecrypticace
Reproduction
https://github.com/saadeghi/tw4alpha-vite-url-bug
it's an empty Vite/Svelte project.
There's
[&_div]:flex
class insrc/routes/+page.svelte
There's a Tailwind plugin insrc/myplugin.js
Logs
Severity
blocking all usage of svelte