Skip to content
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

Classes not being loaded in dev mode until Nuxt dev server is restarted #464

Closed
fabis94 opened this issue Apr 29, 2022 · 16 comments
Closed
Labels
bug Something isn't working

Comments

@fabis94
Copy link

fabis94 commented Apr 29, 2022

Version

@nuxtjs/tailwindcss: 5.0.3
nuxt: 3.0.0-rc.1 (with vite builder)
tailwindcss: 3.0.24

Steps to reproduce

  1. Run nuxt dev server
  2. Add a tailwind class to a Vue component that previously wasn't used anywhere in the project
  3. The new class won't work until you restart dev server

What is Expected?

The class should be added to the page's CSS immediately after it's used for the first time in the project (e.g. in a Vue component).

What is actually happening?

Class doesn't appear, even after refreshing. Only after nuxt is restarted does the new class get added to the page. OR if the tailwind.css file is saved.

(I don't know why a saved change to tailwind.css causes tailwind to see the new class usage, but a saved change to the vue file that actually uses the class doesn't. The vue file is definitely correctly specified under 'content' in the tailwind config, otherwise it wouldn't even work after restarting the dev server)

@fabis94 fabis94 added the bug Something isn't working label Apr 29, 2022
@Owen-Tsai
Copy link

Well, on my end:

  1. The problem doesn't always occur. Sometimes things work perfectly fine, the module is able to pick up changes and reload the view with compiled style rules.
  2. When the changes cannot take effect, I can see a quick flash with expected styles and then quickly disappear, falling back to the "older state" as if there isn't any newly added class. I guess that quick flash is when tailwindcss itself generates tailwind.css output with the correct result, and then when the content of tailwind.css is about to insert into the DOM something unexpected happens which results in the incorrect behavior. The compiled style rule of the new class isn't added in the <style> tag.
  3. When the issue occurs, I guess I have to trigger the compile again to get it working. So I tried to remove the newly added class that cannot take effect, save the file to trigger the compile, and then add it back. The problem is gone, only for a little while. I have to repeat the process every time I encounter the issue. It feels like the content inside the <style> tag is "1 commit behind" the tailwindcss output.

@Aybee5
Copy link

Aybee5 commented Jun 29, 2022

I am experiencing this too. Did anyone find a quick work around?

@munjalpatel
Copy link

munjalpatel commented Jun 30, 2022

I am having the same issue. I am using nutx3 with pnpm if that matters.

@vdtrungok
Copy link

same issue. :((

@sxgrant
Copy link

sxgrant commented Jul 6, 2022

A workaround for local development is to just whitelist every single tailwind class. This adds ~27,000 lines of CSS directly in your head so it's a terrible idea, but it unblocks development - can just disable this config when building for deployments.

in tailwind.config.js:

module.exports = {
  ...
  // Due to issue of class-detection not auto-refreshing
  // Disable this to build for production
  safelist: [
      {
          pattern: /.*/,
      },
  ],
  ...
}

@makkarpov
Copy link
Contributor

makkarpov commented Jul 8, 2022

By the way, I was able to get that issue consistently reproducing under the playground of this module.

The issue starts to reproduce when you add some extra CSS to css tag, e.g.:

export default defineNuxtConfig({
  buildModules: [
    tailwindModule
  ],
  tailwindcss: {
    exposeConfig: true
  },
  css: [
    '@fontsource/inter/400.css',
    '@fontsource/inter/500.css',
    '@fontsource/inter/600.css',
    '@fontsource/inter/700.css'
  ]
})

Also, it requires router to be present, so app.vue won't work, while pages/index.vue will.


@fabis94:

(I don't know why a saved change to tailwind.css causes tailwind to see the new class usage, but a saved change to the vue file that actually uses the class doesn't. The vue file is definitely correctly specified under 'content' in the tailwind config, otherwise it wouldn't even work after restarting the dev server)

Because there is no way for the build system to know dependencies between Vue and CSS, and that HMR should replace the CSS file when your Vue file changes. From bundler point of view these two are completely unrelated, but really CSS content is dependent on markup.

I wonder why HMR even worked in the first place. From my understanding, it shouldn't.

atinux added a commit that referenced this issue Jul 11, 2022
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
@pauljmartinez
Copy link

I resolved this issue by adding ./error.vue to my tailwind.config.js. It seemed like Tailwind needed to look at the contents of this file to be able to include the relevant classes.

module.exports = {
  content: [
    "./components/**/*.{js,vue,ts}",
    "./layouts/**/*.vue",
    "./pages/**/*.vue",
    "./plugins/**/*.{js,ts}",
    "./nuxt.config.{js,ts}",
    "./error.vue",
  ],

@manuel-84
Copy link

manuel-84 commented Apr 26, 2023

same problem with

"@nuxtjs/tailwindcss": "^6.6.5",
"nuxt": "^3.3.3",

when using default Tailwind CSS file from runtime/tailwind.css instead of creating your own

@ineshbose
Copy link
Collaborator

Closing this issue as it is believed to be resolved/stale now - please feel free to comment if it is still an issue in the latest version of the module.

@jshrssll
Copy link

jshrssll commented Aug 5, 2023

This issue is still occuring

"devDependencies": {
  "@nuxt/devtools": "latest",
  "@nuxtjs/tailwindcss": "^6.8.0",
  "@types/node": "^18.17.1",
  "nuxt": "^3.6.5"
}

@fabianwohlfart
Copy link

This issue is still occuring

"devDependencies": {
  "@nuxt/devtools": "latest",
  "@nuxtjs/tailwindcss": "^6.8.0",
  "@types/node": "^18.17.1",
  "nuxt": "^3.6.5"
}

Did you solve it?

@brokuka
Copy link

brokuka commented Apr 9, 2024

bug still exist

"@nuxtjs/tailwindcss": "^6.11.4",
"tailwindcss": "^3.4.3"

@raggesilver
Copy link

raggesilver commented May 1, 2024

Still happening.

  • Operating System: Darwin
  • Node Version: v21.7.3
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: bun@1.1.5
  • Builder: -
  • User Config: devtools, css, postcss
  • Runtime Modules: -
  • Build Modules: -
  • tailwindcss@3.4.3
  • autoprefixer@10.4.19
  • postcss@8.4.38
  • vite@5.2.10

This also happens when I install tailwind manually (without this module). 🤔

@pooya-hajjar
Copy link

same issue . enable disable cache in your browser then refresh that

@ineshbose
Copy link
Collaborator

Definitely sounds like a cache issue to me!

@pooya-hajjar
Copy link

youre welcome buddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests