-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Bug]: live reload rebuild twice when using tailwind watch #714
Comments
Im using jit mode |
@raymclee This is not Remix specific. You can come around this using RSync Take a look at this setup. I used it for my project to eliminate reload twice. |
@raymclee I use tailwind like this |
@edgesoft thanks! It works |
Yeah, at the moment that's just how it is. I'm thinking we should debounce the rebuilds by like 100ms in our watcher and we'd be good. |
Problem with this is it depends on how fast your machine is. May work $5k MacBooks at one debounce interval (that may even be too long), but for someone on an older/slower machine they may need more time. I think we should explore a different approach. Having Tailwind support built-in could be one way :) Or support for customizing postcss a bit. That's one "compiler" that I don't expect we'll change in the future so it's probably safer to expose an experimental API for customizing. |
Instead of adding a workaround to Remix, it could also be an option to try to get postcss to not write files if their content didn't change (there is also existing issue for that postcss/postcss-cli#320). |
This is the real solution 👍 |
That issue isn't quite what we need. That issue just says: "if the input is the same as the output then don't save the file" but what we need is "if the output is the same as what's currently in the output then don't save the file." In any case, I'm going to look into implementing what we need. |
There we go :) postcss/postcss-cli#417 |
Is everyone using postcss-cli? I just tried to use tailwindcss instead of postcss-cli and it does cause rebuilding twice sometime but only reload once. |
ok still reload twice XD |
I am optimistic that the suggested change to In my case #!/usr/bin/env node
import fs from "fs-extra";
import "postcss-cli/index.js";
const PREVIOUS_CONTENT = new Map();
const _outputFile = fs.outputFile;
fs.outputFile = async function outputFile(path, data) {
const prev = PREVIOUS_CONTENT.get(path);
if (prev && prev === data) {
return; // unchanged
}
PREVIOUS_CONTENT.set(path, data);
return _outputFile(path, data);
}; In my - "build:css": "postcss --config ./config/ --dir app/styles styles/global.css",
+ "build:css": "./bin/postcss.mjs --config ./config/ --dir app/styles styles/global.css", Once postcss CLI got the change, I am just going to remove the file and revert the Not pretty, but works at least for me for the time being. |
That workaround works for now, but for anyone coming to this issue later it's very temporary, and we'll have a better solution for this soon! Thanks @rkusa :) |
My PR was merged into postcss-cli! If you update your version to 9.1.0 or greater you should no longer get a double-refresh when you save a file unless you actually do change the CSS (like in the Tailwind JIT case, if you change the class name on an element). In that case you'll still get the double-reload. @ryanflorence had some ideas of how to avoid that once and for all. But the nice this is with postcss-cli 9.1.0 you'll no longer get an unnecessary rebuild :) |
Just upgraded my app: kentcdodds/kentcdodds.com@3f6637c I was able to remove the rsync workaround thing. Here's how things worked without the rsync workaround before postcss-cli 9.1.0: And here's how things work now (still without the rsync workaround) with postcss-cli 9.1.0: Much better :) |
If anyone wants to dig into the tailwind-cli to see whether this sort of change is necessary/would help that would be welcome :) |
Thanks for this awesome improvement @kentcdodds ! |
@kentcdodds I just tried with Tailwind cli and it seems to rebuild twice even if there is no CSS changes. |
same here |
I found a solution on Tailwind side. The same way that you found one for PostCSS. I opened a PR here, if you want to check it out 😄 Also I created a reproduction repository |
It should now be fixed for Tailwind CLI. I'll try again in the next 24 hours (when I can access my laptop). And if it works, I guess we could close the issue. |
So I just tested it and it works fine now for the latest version of Tailwind CLI. However if you add or remove a Tailwind class (so the CSS file changes) there is still a double rebuild. I think this is expected behavior at the moment. Do you think we can close this ticket @kentcdodds ? 😊 |
would |
@girishk21 I wasn't aware of this configuration variable. |
Yeah, we have one more thing to improve this a bit more and it's basically: if the browser gets a notice that a second build has started, wait to refresh even if the first build has finished. Let's leave this open for that. |
Closing for now, as this is an inevitable issue if you're running multiple processes. |
Which Remix packages are impacted?
remix
(Remix core)create-remix
@remix-run/architect
@remix-run/cloudflare-workers
@remix-run/dev
@remix-run/express
@remix-run/netlify
@remix-run/node
@remix-run/react
@remix-run/serve
@remix-run/server-runtime
@remix-run/vercel
What version of Remix are you using?
1.0.6
Steps to Reproduce
Follow the styling section for tailwindcss in remix doc
Expected Behavior
live reload ignore the generated css file change
Actual Behavior
[1] 💿 File changed: app/styles/app.css
[1] 💿 Rebuilding...
[1] 💿 Rebuilt in 226ms
[1] GET /form 200 - - 31.452 ms
[1] 💿 File changed: app/styles/app.css
[1] 💿 Rebuilding...
[1] 💿 Rebuilt in 170ms
The text was updated successfully, but these errors were encountered: