Skip to content

Vue files outside the project dir don't trigger HMR for templates on Windows if imported through a JS file #661

@thecrypticace

Description

@thecrypticace

Related plugins

Describe the bug

If a plugin watches an imported Vue file for changes via addWatchFile() HMR may not trigger template updates for that file depending on the file structure and where things are.

A setup like this could happen for a monorepo structure similar to this:

Shared UI library:
packages/ui/src/index.js
packages/ui/src/example.vue

Vite Project:
apps/web/vite.config.js
apps/web/src/app.vue
apps/web/src/style.css

Interestingly HMR for the <style> blocks does function even when template updates do not.

I'm not sure if this is a bug with this plugin or with Vite. Because of some of the setup required I was thinking Vite but because <style> blocks do work I figured I'd open it here.

I'll note that, as far as I can tell, this bug only affects Windows. I know that macOS is unaffected. I haven't tested on Linux though but I assume it's probably fine there as well.

Reproduction

https://github.com/thecrypticace/vite-windows-hmr-bug

Steps to reproduce

  1. Be on Windows
  2. Setup a project where a Vite project is in a subdir
  3. Add vue files to a directory outside of that subdir
  4. Create a file that re-exports those Vue files' default export (barrel file basically)
  5. Add a plugin that calls addWatchFile on those Vue file paths for some other file
  6. Use those components in an app.vue or something simiar
  7. Try updating them, you'll see HMR does not trigger

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (4) arm64 Apple Silicon
    Memory: 1.79 GB / 7.99 GB
  Binaries:
    Node: 24.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.5.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.15.1 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (139.0.3405.125)
    Internet Explorer: 11.0.22621.3527

(I reproduced this in a VM but not just VMs are affected)

Used Package Manager

npm

Logs

I ran into this when triaging a bug for @tailwindcss/vite with a project that uses a monorepo.

If you want to see that reproduction (though it's much larger than the minimal one I've given) you can see the issue here: tailwindlabs/tailwindcss#18852

If there's further any questions or whatever feel free to ping me and I'll try to clear things up.

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions