vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.1k stars 6.03k forks source link

Vite will add new instance of dat.gui if hot reloaded #1699

Closed fnick851 closed 3 years ago

fnick851 commented 3 years ago

Describe the bug

Vite's hot reload will add a new instance of dat.gui each time to the DOM. (I am actually not 100% sure if this is a bug or it is expected behavior.)

Reproduction

https://github.com/fnick851/vite-shader-water/tree/datgui-issue (on datgui-issue branch)

System Info

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
yyx990803 commented 3 years ago

This is "kind of" expected behavior because:

What you should do is to avoid on-import side-effects in files that export code being used in Vue components - i.e. separate dat-gui setup logic from functions like renderWaterScene.