-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
热更新失效 #7
Comments
would you need to rerun script when modifying template and style? 🤔 and modify script will hmr |
遇到typeError错误时,即使修复问题后,页面也是无法进行热更新,必须手动重新加载页面,之后的热更才是正常的 |
I guess vite call vue runtime interface to rerender the components, but got a error will destroy the component, so we can't rerender only reload 😂 |
应该是这样的,其实对于js文件而言,不存在这个问题,因为vite对于 |
修改.vue文件后,再修改.js文件,就不会热更新了,重新启动一下项目,再更改.js文件,就又可以热更新了 |
可能因为我是macOS,也有可能是因为我用的是 |
我测试了macOS,使用了@vitejs/[email protected],问题依然存在,我截图说明了一下测试流程 |
Vite splits .vue into two files: .css / .js link CSS error report only needs to re-insert the head node. But the js error will cause the internal execution error of vue, because the template+script regenerated by vite will be updated and executed when updating (https://github.com/vuejs/core/blob/main/packages/runtime-core/src/ hmr.ts#L78-L99) However, after the error is reported, the last vdom will be destroyed and the patch(instance.update()) of the rerender cannot be executed. vite内部将.vue拆成两个文件 .css / .js css报错只需要重新插入head节点。 但是js报错会导致vue内部执行错误,因为在更新的时候会将vite重新生成的template+script 更新执行 https://github.com/vuejs/core/blob/main/packages/runtime-core/src/hmr.ts#L78-L99 但是报错后会破坏上次的vdom 导致没办法执行rerender的patch(instance.update()). |
may be the rerender script don't exec the setup lifecycle will exec in the Component setup first time.and the Component is not exec the destroy so no exec the setup Script. you can chance to destroy the |
但是不修改.vue,只修改.js的情况下,页面是可以热更新的,只有在修改了.vue的前提下,再修改.js才不会热更新 |
我本地Mac ,js始终无法更新 |
当我引入一些自定义组件的时候,页面会报出警告,提示我无法识别这个自定义组件,从而无法在页面显示。重启之后就显示正常! |
遇到同样问题,父组件引入新创建的子组件,热更新编译报错,提示不认识子组件;js文件添加变量引入到父组件也会报错,每次都要重新启动项目。@vitejs/plugin-vue版本3.1.0 |
没有办法解决吗? |
快2年了,也没有解决呀,vite的hmr限制写法太多了 😂 |
@vitejs/plugin-vue 有这段代码 // check if the template is the only thing that changed
if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
output.push(`export const _rerender_only = true`)
}
output.push(
`import.meta.hot.accept(mod => {`,
` if (!mod) return`,
` const { default: updated, _rerender_only } = mod`,
` if (_rerender_only) {`,
` __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render)`,
` } else {`,
` __VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated)`,
` }`,
`})`,
) 中有一个_rerender_only的变量,当@vitejs/plugin-vue发现当前代码非首次构建,而且当前只有template标签中发生变化的时候,就会把_rerender_only 设置为true。 _rerender_only 为true时,热更新会执行 VUE_HMR_RUNTIME.rerender(xx) 这个函数并不会重新获取组件中的最新的状态值(例如重新执行setup函数得到最新的值),而从外面导入的值就在setup函数中。 其中判断是否只有template发生变化的isOnlyTemplateChanged代码如下:
当script没有发生变化,styles没有发生变化,customBlock没有发生变化的时候,这边默认认为只有template发生了变化。但是当我们修改了外面引入的文件时候同样满足了上述情形,导致了插件认为我们只需要rerender,导致没有获取到最新的setup中的值。 |
测试用到的版本如下: {
"name": "my-vite-vue-demo",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.21"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"sass": "^1.75.0",
"vite": "^5.2.0"
}
} ** 这是bug还是特性吗?为什么这么长时间没有解决这问题 ** |
The underlying problem is: I've made a PR. please try these pre-releases packages. |
Describe the bug
在index.vue中import testClass,这时候修改testClass,可以输出console。但是修改index.vue后,再次修改testClass,就不会输出console了
Reproduction
https://github.com/ningbnii/vite2_vue3_hmr_test
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: