import { $count } from "./a";
import { inc, dec } from "./b";
import { useStore } from "effector-react";
import React from "react";
export function App() {
const count = useStore($count);
return (
<>
<div>Count: {count}</div>
<button onClick={() => inc()}>+</button>
<button onClick={() => dec()}>-</button>
</>
);
}
When we start project this files will be compiled and executed by compiler, so we will have one set of units and connections. But when we make a change, vite's hmr will replace changed module and the compiler compiles and executes the changed module again. After all we have two copies of units and connections. Thus, we get a copy for each replaced module.
How to reproduce:
make change in the beginning of the b.ts file
increase or decrease counter
check console, when logger effect fired twice
What I think about possible solutions.:
For the second issue: we could create domain for each module and wrap up all content of module in withRegion, and when hmr is fired we could clean replaced module
For both issues: we need a more stable sids that is not related from position in file and can keep between hmr
There are two issues related with hot module replacement(HMR), these issues is following:
For example we have two files
a.ts
andb.ts
:When we start project this files will be compiled and executed by compiler, so we will have one set of units and connections. But when we make a change, vite's hmr will replace changed module and the compiler compiles and executes the changed module again. After all we have two copies of units and connections. Thus, we get a copy for each replaced module.
How to reproduce:
What I think about possible solutions.: