-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[v4] Usage of @tailwindcss/postcss^4.0.0-alpha.25
with svelte-preprocess
for svelte file with style tag: problematic dependency scanning
#14973
Comments
@vnphanquang We can look into the warning but it's going to be hard to make sure all of Tailwind CSS is within 10 external files. This whole number sounds like a very arbitrary limit though. However, we can investigate! The stack exceed seems unrelated to this. Having more dependencies does not mean the stack will grow unbound. Do you have a trace for what's causing the stack to go up? Any symbols to figure out what's causing the recursion would be super helpful! |
@philipp-spiess thanks for replying. Yeah I suspect this is very tightly coupled with how svelte-preprocess works. 10 is set by the Svelte team as an indicator of potentially problematic setup, hence the warning, but it is arbitrary indeed. However, the emitted dependency file list contains almost all source files in the project, including svg assets. I omitted the full list in the report because it is long, you can give it a look by running So if I have a total of 100 source files (ts,js,json,svg,svelte,...), and 10 svelte files with I've been digging (and will continue to) but up til now there isn't any other symbol that led to the observed output. As long as the svelte file contains a style tag, the first warning will print. And as long as the total of compatible source files are above 10, the second one will do. Regarding the stack exceeding, yeah you're right, it might not be direct causation but perhaps some correlation at least. Will keep an eye on it. I wonder how v4 is different than v3 in its postcss implementation, especially since I never observed such issue in v3 : 🤔 Optimally, now that v4 makes very good use of custom properties, I wish there were an escape hatch to avoid svelte style tag being processed by tailwind at all. In our v4 setup all tailwind goodies are in CSS files. |
@vnphanquang Thanks! did not look into this in detail yet but one thing I saw in your repro is that you're using Tailwind as a postcss plugin instead of the Vite plugin. Now, we currently have an issue in the current version of the Vite plugin (fixing it here) but once this is resolved, it would be awesome if you can help try this instead. We do think that all Vite setups (including SvelteKit) would greatly benefit from using the Vite plugin instead of the postcss one, since it's much faster in development as it needs to scan much less modules for potential classnames. |
Thanks @philipp-spiess. I will definitely give it a try. In fact, as I stated in the issue description, I would too prefer the Vite plugin but to reiterate we're relying on some postcss plugins which work well with tailwind in dev, but do not apply to the tailwind related css files during production build for some reason. Will look into it some more. |
@vnphanquang Hey! Me again :) We pushed another alpha release yesterday that contains the updates to the Vite plugin that I mentioned above. Would be really cool if you could give that a try over the postcss extension 👍 You're still able to use postcss plugins with the Tailwind CSS Vite plugin, it just gives Tailwind a bit more control as we're able to process the CSS before other plugins see it (and it allow us to avoid having to scan the file system because of how the Vite module graph works) |
@philipp-spiess thanks. Gave the latest alpha release a try (4.0.0-alpha.34), and still having the same problem I described earlier. I've put together a minimal repro here: https://github.com/vnphanquang/tailwind-4-alpha-postcss-plugins-reproduction. This is a completely different problem so I'm happy to open another issue, but related here as this is essentially the reason blocking me from using the Vite plugin, hence the use case for using Tailwind as a PostCSS plugin. |
@philipp-spiess Still happening in beta.1 FYI. I'm having another problem where if app A imports some tailwind css from package B that uses a plugin C. That is A imports B, B imports C. I'll get this:
This is when using tailwind as a postcss plugin in Vite context. Reproduction is here: https://github.com/vnphanquang/tailwind-4-postcss-deep-plugin-reproduction. Again. I'm happy to open a separate issue, just let me know. Thanks a lot for the work good. |
Version
@tailwindcss/postcss^4.0.0-alpha.25
&tailwindcss^4.0.0-alpha.25
, i.e all versions of v4 alpha from 25 to 33 (as of this writing).Environment
Output of
npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite,tailwindcss,@tailwindcss/postcss}"
:Reproduction
https://github.com/vnphanquang/sveltekit-tailwind-4-reproduction. Please see README for steps.
Description
Note
Please note that tailwind is being used as a
postcss
plugin here, reported issue is not observed when usingvite
plugin.In the reproduction, any
svelte
file with astyle
tag will cause the following two warnings fromsvelte-preprocess
during bothdev
andbuild
:There have been instances where similar warning was observed: sveltejs/svelte-preprocess#619, sveltejs/svelte-preprocess#346. But I don't exactly know what is causing this now. I'm guessing parsing
style
tags calls for parsing Tailwind entry css, which in turns requires parsing all matching source files 🔄.Similarly, this is causing a lot of parsing during dev. In our real project with lots of such svelte files, the server quickly crashed with
Maximum Call Stack Size Exceeded
.Use case
Hi all thanks for the good work, Tailwind 4 has been really good and I'm trying to test it out on some existing v3 projects with relatively complex setup. In our case we use tailwind as a postcss plugin because we also rely on some other postcss plugins (mixins, custom properties, custom media queries). We tried to use tailwind as vite plugin which works well in dev but the plugins do not apply during production build.
The text was updated successfully, but these errors were encountered: