Skip to content

HMR with an external script does not proper reload #8

Closed
@cub

Description

@cub

Describe the bug

I have a problem with HMR with Vue. When I modify my external script, HMR reload the .vue but stay in an old state.

<!-- test-hmr.vue -->
<template>
  <div class="test-hmr">
    TestHmr !
    {{ qqq }}
  </div>
</template>
<script lang="ts" src="./test-hmr.ts"></script>
// test-hmr.ts
import { defineComponent } from 'vue';
export default defineComponent({
  name: 'TestHmr',
  data() { return { /* qqq:'weeeeeeee' */ }; }
});

I see in the console the warning [Vue warn]: Property "qqq" was accessed during render but is not defined on instance., it's normal.
Then I uncomment qqq:'weeeeeeee' and save the .ts.
I see in the console [vite] hot updated: /src/components/test-hmr/test-hmr.vue.
But the render is not showing the weeeeeeee, it's stuck with the not defined previous state.

On the very first load, it reload/refresh nicely. If you rename the qqq to something else in the .vue, save, then edit accordingly the .ts, it will stuck in previous state.

Note, if I insert the content of my .ts inside the <script>, the HMR works well.
The problem only occurs with external script file.

Reproduction

https://github.com/cub/test-hmr

System Info

System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 8.83 GB / 15.50 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/bin/node
    npm: 8.5.4 - /usr/bin/npm
  Browsers:
    Chrome: 99.0.4844.51
    Chromium: 99.0.4844.51
    Firefox: 98.0.1
  npmPackages:
    @vitejs/plugin-vue: ^2.2.4 => 2.2.4 
    vite: ^2.8.6 => 2.8.6

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeat: hmrp3-minor-bug 🔨An edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions