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

Vue HMR does not work unless component has an active instance #5221

Closed
7 tasks done
ElMassimo opened this issue Oct 7, 2021 · 2 comments
Closed
7 tasks done

Vue HMR does not work unless component has an active instance #5221

ElMassimo opened this issue Oct 7, 2021 · 2 comments

Comments

@ElMassimo
Copy link
Contributor

ElMassimo commented Oct 7, 2021

Describe the bug

This bug is related to #131, and is the same one described in vuejs/core#4757.

For example, in a Vue app with Vue Router:

When a page component file is modified, if the page:

  • is the current route HMR works.
  • is not the current route, HMR does not work

As a result, when modifying a component that is not the current route, the HMR update is sent as usual, but because the component has no active instances, the Vite client does not update the module.

If the modified page component has already being imported, when its route is visited, the original module is used, which doesn't include the changes since it was never updated by HMR.


It's not specific to Vue Router though, it could happen for any development flow where a component is imported, but it might not have an active instance.

For example:

<Welcome v-if="condition"/>

If Welcome.vue is modified when the condition is false, then once the condition is true, an outdated version of the component will be rendered.

The reason I mention Vue Router first, is that it's a very typical way for users to experience the bug.

Reproduction

github.com

System Info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-3635QM CPU @ 2.40GHz
    Memory: 53.61 MB / 8.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 16.5.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.19.1 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 94.0.4606.71
    Firefox: 91.0
    Safari: 14.0.1
  npmPackages:
    @vitejs/plugin-vue: ^1.9.3 => 1.9.3
    vite: ^2.6.3 => 2.6.4

Used Package Manager

pnpm

Logs

No response

Validations

@ElMassimo
Copy link
Contributor Author

Since plugin-vue is still providing _sfc_main as a second parameter to the HMR createRecord function, it's likely that it can be fixed in vue-next instead.

@ElMassimo
Copy link
Contributor Author

Fixed in vuejs/core@9e3d773

@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants