-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 @apply breaks with Svelte 5 (alpha 57) #10513
Comments
darkMode: ['variant', '&:where(:global(.dark), :global(.dark) *)']
darkMode: ['variant', ['&:where(.dark, .dark *)', '&:where(:global(.dark), :global(.dark) *)']] I'm not sure if this is the best practice, but it works for the current changes. |
The generated CSS is this: main.svelte-11sclw {
/* tailwind @apply with 'dark:' breaks in alpha 57 */
--tw-bg-opacity:1;
background-color:rgb(219 234 254 / var(--tw-bg-opacity));
}
/* (unused) :is(html.dark-mode main) {
--tw-bg-opacity:1;
background-color:rgb(30 58 138 / var(--tw-bg-opacity));
}*/
button.svelte-11sclw {
width:50px;
aspect-ratio:1/1;
border-radius:10px;
background:black;
/* regular css works */
}
html.dark-mode button.svelte-11sclw {
filter:invert(1);
} The problem is that Tailwind generates CSS which contains selectors that look unused to Svelte. The solution is to add adjust the Tailwind config by adding /** @type {import('tailwindcss').Config} */
export default {
- darkMode: ["class", "html.dark-mode"],
+ darkMode: ["class", ":global(html.dark-mode)"],
content: ["./src/**/*.{html,js,svelte,ts}"],
theme: {
extend: {},
},
plugins: [],
}; Question: Was this an existing config from a Svelte 4 project? If so, we may need to adjust the breaking changes section to note that Svelte now supports |
Yes. A config that worked from Svelte 4 up to and including Svelte 5 Alpha 56. Edit: <div class="dark:bg-blue-900"/>
<!-- even with breaking changes in alpha 57, this still worked-->
<!-- Breaks with your tailwind config :global() suggestion --> |
Reopening and giving it the documentation level - we should note this in the breaking changes. |
Unfortunately, this isn't a fix. While it does fix the cases where Edit: Here's a REPL that I find to be a just bit easier to play with and demonstrate. |
With great pain comes great responsibility ... TL;DR: Uno continues working; Tailwind breaks from Svelte 5 Alpha 57 I went ahead and made a Stackblitz for UnoCSS and Tailwind. In the <style> section of the svelte component the:
|
REPL, after modifying /** @type {import('tailwindcss').Config}*/
const config = {
- darkMode: "class",
+ darkMode: ['variant', ['&:where(.dark, .dark *)', '&:where(:global(.dark), :global(.dark) *)']],
content: ["./src/**/*.{html,js,svelte,ts}"],
theme: {
extend: {},
},
plugins: [],
};
module.exports = config; |
@mwc yes this is a solution, but I would venture to say it's not a satisfactory one since:
Personally with Tailwind I have just left things inline or have moved things to the style section like: <style lang="postcss">
.some-class {
@apply some-utility-classes;
:global(html.dark) & {
@apply some-more utility-classes;
}
}
</style> |
It works with v119, can we close this? |
No? There's multiple demos to choose from here:
|
This works, but for the
|
with this solution, I am getting |
Describe the bug
Video shows it best; starting with alpha 57 the tailwind @apply rule breaks (specifically with darkmode):
tailwind-break-alpha-57.mp4
Reproduction
SvelteLab
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: