Vite + router + tailwind JIT -> full page reload
See original GitHub issueDescribe the bug
Follow up of #4147 , when editing Vue templates, I get full page reload instead of HMR.
Reproduction
https://github.com/jods4/bug-vite-tailwind/
Go into HelloWorld.vue, change the class bg-yellow-400 into bg-green-400.
Notice on the terminal or in the browser that vite triggered a full page reload. I’d expect HMR here.
I first tried without Vue router and it worked, so I’m not sure where the problem lies exactly.
System Info
System:
OS: Windows 10 10.0.18363
CPU: (12) x64 Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
Memory: 5.05 GB / 15.79 GB
Binaries:
Node: 15.5.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
npm: 7.3.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.18362.1593.0)
Internet Explorer: 11.0.18362.1
npmPackages:
@vitejs/plugin-vue: ^1.2.2 => 1.2.4
vite: ^2.3.3 => 2.4.1
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:22 (11 by maintainers)
Top Results From Across the Web
Just-in-Time Mode - Tailwind CSS
Enabling JIT mode. To enable just-in-time mode, set the mode option to 'jit' in your tailwind.config ...
Read more >vue router reload page - You.com | The search engine you control.
vue-router route with params not working on page reload ... vitejs/viteVite + router + tailwind JIT -> full page reload#4150. Created over 1...
Read more >vite-plugin-full-reload VS vite_ruby - LibHunt
Compare vite-plugin-full-reload vs vite_ruby and see what are their differences. ... Automatically reload the page when files are modified (by ElMassimo).
Read more >Tailwind is not refreshing when working with vite + react
Turns out, I originally created the file header.tsx and immediately changed it to Header.tsx, then imported it in App.tsx but it was ...
Read more >Vite + React + React Router + Tailwindcss JIT Template - Reddit
https://github.com/vivekascoder/vite-react-tailwind-jit. In case you use vue ... [Request] PSP - Baryon Sweeper Complete Guide.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@patak-js thanks, learned something new today. I linked #4267 and can confirm that it resolves the issue, HMR works as expected 🎉
I tried to revert 09c6c94690ea3fc8b66bb6781995b3e15faedf8f locally, hmr triggers on
index.csswithout page reload when updatingPage.vue, but the component itself doesn’t update.Edit:
HMR is broken with tailwindcss (jit mode) since 2.3.7 (component simply won’t update). The fix introduced in 2.4.1 (09c6c94690ea3fc8b66bb6781995b3e15faedf8f) makes it doing a full page reload instead of doing nothing.
Edit 2:
After editing
Page.vue, its update is propagated (propagateUpdate) withindex.cssas an importer, leading to this code to be called : https://github.com/OneNail/vite/blob/328a2940963e52f1bf30412564624ff1715155cb/packages/vite/src/node/server/hmr.ts#L247-L256This is the object received by
propagateUpdate():I’m not sure why
routes.tsis not part of the importers listIIUC, tailwind tells postcss to register all the purgeable files as a dependencies and so this is being called : https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts#L674 leading to
Page.vuebeing a deps ofindex.cssThis precise case could be fixed by importing
index.cssfrommain.jsinstead of being a link inindex.html(somehowroutes.tsbecomes an importer in addition toindex.cssin that case. But then the same issue could arise for SFC at the end of the chain. (Edit 3: I added another test case for this here : https://github.com/paraboul/vue-hmr-reload/tree/alt)I’m laking a bit of context here to go forward with a fix.
Edit 4 :
Overall it seems that the issue is that Tailwind (JIT) generated css (
index.css) somehow mess up with theimporterslist of SFC and strips any other importers in some cases.