question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite + router + tailwind JIT -> full page reload

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:15
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
lhermanncommented, Jul 19, 2021

@patak-js thanks, learned something new today. I linked #4267 and can confirm that it resolves the issue, HMR works as expected 🎉

7reactions
paraboulcommented, Jul 17, 2021

I tried to revert 09c6c94690ea3fc8b66bb6781995b3e15faedf8f locally, hmr triggers on index.css without page reload when updating Page.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) with index.css as an importer, leading to this code to be called : https://github.com/OneNail/vite/blob/328a2940963e52f1bf30412564624ff1715155cb/packages/vite/src/node/server/hmr.ts#L247-L256

This is the object received by propagateUpdate() :

  id: null,
  file: '/Users/anthonycatel/dev/bug-vite-tailwind/src/views/Page.vue',
  importers: Set(1) {
    ModuleNode {
      id: '/Users/anthonycatel/dev/bug-vite-tailwind/index.css?direct',
      file: '/Users/anthonycatel/dev/bug-vite-tailwind/index.css',
      importers: Set(0) {},
      importedModules: [Set],
      acceptedHmrDeps: Set(0) {},
      isSelfAccepting: true,
      transformResult: null,
      ssrTransformResult: null,
      ssrModule: null,
      lastHMRTimestamp: 1626186072440,
      url: '/index.css?direct',
      type: 'css'
    }
  },
  importedModules: Set(0) {},
  acceptedHmrDeps: Set(0) {},
  isSelfAccepting: false,
  transformResult: null,
  ssrTransformResult: null,
  ssrModule: null,
  lastHMRTimestamp: 1626186072440,
  url: '/@fs//Users/anthonycatel/dev/bug-vite-tailwind/src/views/Page.vue',
  type: 'js'
}

I’m not sure why routes.ts is not part of the importers list

IIUC, 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.vue being a deps of index.css

This precise case could be fixed by importing index.css from main.js instead of being a link in index.html (somehow routes.ts becomes an importer in addition to index.css in 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 the importers list of SFC and strips any other importers in some cases.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found