You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the development environment of our project with Vite + Vue2.7 + Vuex + Vue Router, we encountered an issue where there is a circular reference between src/store/modules/user.js and src/router/index.js. Modifying any JSX code seems to cause the state of src/store referenced elsewhere (src/utils/permission.js) to be reset after HMR. We have to refresh the page, which is very bad for the development experience.
youthug
changed the title
When using JSX and there is a circular dependency, the component state will be reset
The state data of Vuex may be reset when using JSX, if there is a circular dependency
Dec 25, 2024
I found a simpler way to fix this. Add the following code in src/store/index.js. Not sure if it will have any unexcepted effects.
if(import.meta.hot){// for tree-shakingimport.meta.hot.accept(['./modules/user.js',],()=>{// Not handling hot updates;// the purpose is to resolve the issue where the state is reset// after Vite HMR due to circular dependencieswindow.location.reload()},)}
Describe the bug
In the development environment of our project with Vite + Vue2.7 + Vuex + Vue Router, we encountered an issue where there is a circular reference between
src/store/modules/user.js
andsrc/router/index.js
. Modifying any JSX code seems to cause the state ofsrc/store
referenced elsewhere (src/utils/permission.js
) to be reset after HMR. We have to refresh the page, which is very bad for the development experience.Reproduction
https://github.com/youthug/vite-vuex-state-repro.git
Steps to reproduce
git clone https://github.com/youthug/vite-vuex-state-repro.git cd vite-vuex-state-repro yarn yarn dev
src/components
folder to see the changes on the page.System Info
Used Package Manager
yarn
The text was updated successfully, but these errors were encountered: