tailwindcss: Hot reloading does not work for HTML templates
Version
@nuxtjs/tailwindcss: 4.1.1 nuxt: 2.15.6
Reproduction Link
https://rechenknecht.net/lmm/nuxt-tailwind-bug-report
Steps to reproduce
- Clone repo
- Run
yarn dev - Change any text in
pages/index.vue(e.g. schaukasten -> schaukasten2)
What is Expected?
- Hot reloading should work
What is actually happening?
- Text is not updated until page in browser is manually refreshed
- A loading indicator is shown in the bottom right corner (file change is detected)
Notes
- Hot reloading works for removing components in the template (e.g. removing or adding the
Logocomponent) - Hot reloading works for scripts
- Hot reloading works for styles
- Works with other UI frameworks like vuetify
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 23
- Comments: 55
I managed to pinpoint the issue, for more details see: https://github.com/nuxt/postcss8/issues/24
Temporary Fix
You’re likely experiencing this issue if you’re:
2.15.4or later;@nuxtjs/tailwindcss 4, your are).Disabling
icsscompile type in your build options should fix the issue (but might introduce others if you’re relying on SASS, see: https://github.com/nuxt/nuxt.js/pull/9014):Cheers!
Good day…
I have been playing around with it for a bit, and i noticed that it keeps working fine when there is no other css defined within
<style></style>, once you add anything to it id,class,etc it stops the hot reload from working, removing it again needs a manual refresh to allow the hot reload to start working again, inline styles seem to work fine as well,this also only seems to happen when the styles are defined within that component or page, as when defining a scoped style in
layout/default.vuethis does not effect the hot reload of let say thepages/index.vueso a kind of bad workaround would be, to not define any styles within the style tags, and put everything inline…
i hope this gets fixed soon, as this kind of sucks… i would help my self but i would not know were to start…
kind regards.
Good day again…
I have been playing around some more and have a little update, that when there is something commented out withing the style tags, as in if there is any form of type inside the style tags, hot reload stops working,… i have been looking into hot-update.js but i cant make heads or tails of it… as it seems the updates are being pushed through. as the hot-update does show the modification,… its just seems to not updating the DOM accordingly…
also removing tailwind from build modules does not solve the problem, only removing postcss with removal of node_modules and package-lock.json, will fix the problem. so i suspect that postcss is interfering with webpack somehow. as even when tailwindcss in not active in nuxt.config.js hot reload still is not working…
UPDATE!.. WORKAROUND! edit package.json whith the following versions,
"devDependencies": { "@nuxtjs/tailwindcss": "~3.4.3", "postcss": "~7.0.36" }rm -rf node_modules package-lock.jsonnpm installthis fixed the problem for me… cheers!!!
Any progress on this bug…? Or maybe a workaround… ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any news on this. is it being worked on ?
Any updated on this with latest v5 version and Tailwind 3? I still have this issue, HMR is not working if previously not used Tailwind class is added to template, it reloads whole page:
A workaround that I’ve found to keep working with this module (and with any nuxt module that depends on @nuxt/postcss8), is to add this to your project package resolutions:
Is there any solution that does not involve downgrading to PostCSS v7?
The workaround works but it downgrades Tailwind to v1.9.x which disables other handy features of Tailwind 2.x like arbitrary values. So it would be great if we could find a better solution which works with the latest included Tailwind version 2.x.
An alternative workaround is to downgrade to v4.1:
"@nuxtjs/tailwindcss": "~4.1.0",This will use Tailwind 2.x and hot-reloading will work. But on that version, there’s another bug where it does the HMR twice, see #369commenting the
./nuxt.config.{js,ts}',line seemed to fix it 😃 https://github.com/nuxt-community/tailwindcss-module/issues/406#issuecomment-998760314Here’s an easy way to reproduce the issue:
npx create-nuxt-appand generate a new Nuxt projectnpx tailwindcss initto create a Tailwind config filetailwind.config.jsand addmode: 'JIT',to enable the JIT compilernpm run devPreserve login the Dev Tools’ console/components/Tutorial.vueand add an arbitrary value to an element, e.g.bg-[#ee3456][HMR] The following modules couldn't be hot updated: (Full reload needed)Expected: To see the changes without page reload, using HMR.
The issue appears to be related to how Tailwind JIT “caches” the previously used classes. Continuing from the previous steps:
bg-[#ee3456]to something else, e.g.bg-[#ee3457]bg-[#ee3456]The moment you add a class, whether built-in or arbitrary, which Tailwind (or the CSS loader?) has never seen before, it will cause HMR to break. Once the class has been cached somehow, HMR will work okay.
In the above message, it contains all the instructions and even has an example installation.
indeed that is the case … its deff not ideal but it the only combination i found that works… regards.
I’m having the same issue