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

Disabling HMR Prevents Tailwind from Updating #10270

Closed
7 tasks done
digitalam025 opened this issue Sep 28, 2022 · 2 comments · Fixed by #11506
Closed
7 tasks done

Disabling HMR Prevents Tailwind from Updating #10270

digitalam025 opened this issue Sep 28, 2022 · 2 comments · Fixed by #11506
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@digitalam025
Copy link

digitalam025 commented Sep 28, 2022

Describe the bug

I disabled HMR because it causes every tab to reload, whereas what I need is that only 1 tab to be reloaded while others stay put for me to compare the style changes visually.

By setting server.hmr to false, it does what I want, to stop HMR. But on a manual refresh in the browser, the Tailwind styles don't get updated. As if the JIT engine doesn't get re-ran.

I've discussed this not in Vite's Discord but Laravel's. But I don't think this is such a specific issue.
Link to the post here: https://discord.com/channels/297040613688475649/1024554528734969857

In the reproduction link below:

  1. Replace text-red-500 with any other style, such as text-yellow-500 or text-2xl etc.
  2. Save the file (index.html) and manually hit reload.
  3. Notice that the style is not changed and reset to as if there were no styles present.

Reproduction

https://stackblitz.com/edit/vitejs-vite-wwtrrb?file=index.html&terminal=dev

System Info

System:
    OS: Linux 5.10 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (6) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 1.41 GB / 3.84 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    npm: 8.7.0 - ~/.nvm/versions/node/v16.14.0/bin/npm
  npmPackages:
    @vitejs/plugin-vue2: ^1.1.2 => 1.1.2 
    vite: ^3.1.0 => 3.1.0

Used Package Manager

npm

Logs

No response

Validations

@russelldavis
Copy link
Contributor

russelldavis commented Dec 23, 2022

I hit the same issue, using the latest version of vite (4.0.3) and the latest tailwind (3.2.4). Here's my workaround:

  1. Instead of running vite dev, run vite build --watch --minify false --outDir dist-dev --mode development.
  2. To serve the output from step 1, use any static http server in the dist-dev directory, e.g. https://github.com/vercel/serve (you can just run npx serve).

UPDATE: A much better workaround (that doesn't require running vite in build mode):

  1. Install ws as a dev dependency (npm i -D ws @types/ws)
  2. Add this to the top of vite.config.ts:
const wss = new WebSocketServer({port: 0}); // 0 means find a free port
  1. Update your vite config to have this entry:
  server: {
    hmr: {
      clientPort: (wss.address() as AddressInfo).port
    }
  }

This creates a no-op websocket server and tells the client to talk to it instead of vite's server, effectively disabling any hmr updates.

russelldavis added a commit to russelldavis/vite that referenced this issue Dec 27, 2022
In the non-hmr path, when invalidating a module, it wasn't invalidating
the importers. This meant that CSS dynamically generated based on a
module's contents (e.g., what tailwind does) would not regenerate
when refreshing a page.

The HMR code path already invalidated importers, which is why the bug
didn't exist with HMR enabled. This change makes the invalidation
consistent between HMR and non-HMR.
russelldavis added a commit to russelldavis/vite that referenced this issue Dec 27, 2022
In the non-hmr path, when invalidating a module, it wasn't invalidating
the importers. This meant that CSS dynamically generated based on a
module's contents (e.g., what tailwind does) would not regenerate
when refreshing a page.

The HMR code path already invalidated importers, which is why the bug
didn't exist with HMR enabled. This change makes the invalidation
consistent between HMR and non-HMR.
russelldavis added a commit to russelldavis/vite that referenced this issue Dec 27, 2022
In the non-hmr path, when invalidating a module, it wasn't invalidating
the importers. This meant that CSS dynamically generated based on a
module's contents (e.g., what tailwind does) would not regenerate
when refreshing a page.

The HMR code path already invalidated importers, which is why the bug
didn't exist with HMR enabled. This change makes the invalidation
consistent between HMR and non-HMR.
@russelldavis
Copy link
Contributor

I submitted a PR that fixes this: #11506

@sapphi-red sapphi-red added feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) has pr and removed pending triage labels Dec 31, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants