vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.41k stars 9.58k forks source link

Vuex Devtools plugins registered on server which increases memory usage #2250

Open urbnjamesmi1 opened 4 months ago

urbnjamesmi1 commented 4 months ago

Version

4.0.2

Describe the bug

Recently upgraded Vuex to 4.0.2 for a Vue 3 migration that uses a custom SSR solution using Express and Webpack. When running in development mode, the server's memory continued to rise with usage, whereas in production mode, it didn't happen.

Ran a profiler via Chrome's devtools and noticed that in development mode, there were large memory allocations for the VUE_DEVTOOLS_PLUGINS. We also use vue-i18n and vue-router which also register devtools plugins when running in development mode.

However, those other libraries make a check that they are executing in the browser or not in a Node environment, but Vuex does not. As long as you are running in development mode (even on the server) it registers the devtools plugins. I believe this is the cause of the sustained memory usage (possibly a leak?).

I will submit a PR to fix this issue.

Reproduction

  1. Use Vuex 4.0.2 with Vue 3 with SSR on a Node server process while running with NODE_ENV=development
  2. Make sure the usage includes registering store modules at runtime
  3. Notice that as the server processes more requests that use Vuex, the memory used by the server will rise and not come down.
  4. Notice that the same thing doesn't happen if you run the server with NODE_ENV=production

Expected behavior

Vuex not to add devtools on the server (even if NODE_ENV=development), client-side is fine.

Additional context

No response

Validations