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

HMR with an external script does not proper reload #8

Closed
7 tasks done
cub opened this issue Mar 15, 2022 · 8 comments · Fixed by #471
Closed
7 tasks done

HMR with an external script does not proper reload #8

cub opened this issue Mar 15, 2022 · 8 comments · Fixed by #471
Labels
bug Something isn't working feat: hmr p3-minor-bug 🔨 An edge case that only affects very specific usage (priority)

Comments

@cub
Copy link

cub commented Mar 15, 2022

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

@sapphi-red
Copy link
Member

I was not able to reproduce with your repro.
https://stackblitz.com/github/cub/test-hmr?file=src%2Fcomponents%2Ftest-hmr%2Ftest-hmr.vue,src%2Fcomponents%2Ftest-hmr%2Ftest-hmr.ts

Does it only happen in a specific environment? And does it still happen with Vite 3?

@github-actions
Copy link

github-actions bot commented Aug 3, 2022

Hello @cub. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@cub
Copy link
Author

cub commented Aug 3, 2022

Uncomment the qqq, the 'weeeeeeee' appear ✅
Change the variable in .vue to qqqq, the 'weeeeeeee' disappear ✅
Change the variable in .ts to qqqq, the 'weeeeeeee' do not appear ❌

chrome_gm2Rm8407q.mp4

@cub
Copy link
Author

cub commented Aug 3, 2022

And yes @sapphi-red , it still happen with Vite 3

@haoqunjiang haoqunjiang transferred this issue from vitejs/vite Dec 3, 2022
@haoqunjiang haoqunjiang added feat: hmr bug Something isn't working labels Dec 3, 2022
@cub
Copy link
Author

cub commented Dec 16, 2022

Still happen with vite 4.0.1 and @vitejs/plugin-vue 4.0.0 (latest version at this time).

@tehomen
Copy link

tehomen commented Nov 16, 2023

This issue is still happening. When you first start vite, you'll be able to change content in ts file and it will update, but after making a change to anything within the vue template if you change anything within the ts file that the template references vite says it updated but no updates are actually made to the page.

@EmilieOLIVIE
Copy link

EmilieOLIVIE commented Apr 3, 2024

The issue seems to stem from the following line in main.ts:

// check if the template is the only thing that changed
if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
  output.push(`export const _rerender_only = true`)
}

A temporary workaround is to change export const _rerender_only = true to export const _rerender_only = false in order to force the rerender in all cases, when separate script/template files are involved.

Maybe add a setting to vite to allow cache disabling?

EmilieOLIVIE added a commit to EmilieOLIVIE/vite-plugin-vue that referenced this issue Apr 3, 2024
@edison1105 edison1105 added the p3-minor-bug 🔨 An edge case that only affects very specific usage (priority) label Sep 25, 2024
@edison1105
Copy link
Member

edison1105 commented Nov 9, 2024

duplicate of #7. please try these pre-releases packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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.

6 participants