]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(devtools): use flag to include devtools
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 Aug 2022 12:44:31 +0000 (14:44 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 Aug 2022 13:02:38 +0000 (15:02 +0200)
packages/pinia/src/createPinia.ts
packages/pinia/src/env.ts
packages/pinia/src/vue2-plugin.ts
rollup.config.js

index 8279b4e9e51b2b3a6c7ae494a616e47916c52f06..f71497fd31a865c6bbfe2eb124d4b38bcaf5d0ba 100644 (file)
@@ -1,7 +1,7 @@
 import { Pinia, PiniaPlugin, setActivePinia, piniaSymbol } from './rootStore'
 import { ref, App, markRaw, effectScope, isVue2, Ref } from 'vue-demi'
 import { registerPiniaDevtools, devtoolsPlugin } from './devtools'
-import { IS_CLIENT } from './env'
+import { USE_DEVTOOLS } from './env'
 import { StateTree, StoreGeneric } from './types'
 
 /**
@@ -29,7 +29,7 @@ export function createPinia(): Pinia {
         app.provide(piniaSymbol, pinia)
         app.config.globalProperties.$pinia = pinia
         /* istanbul ignore else */
-        if (__DEV__ && IS_CLIENT) {
+        if (USE_DEVTOOLS) {
           registerPiniaDevtools(app, pinia)
         }
         toBeInstalled.forEach((plugin) => _p.push(plugin))
@@ -56,9 +56,8 @@ export function createPinia(): Pinia {
   })
 
   // pinia devtools rely on dev only features so they cannot be forced unless
-  // the dev build of Vue is used
-  // We also don't need devtools in test mode or anywhere where Proxy isn't supported (like IE)
-  if (__DEV__ && IS_CLIENT && !__TEST__ && typeof Proxy !== 'undefined') {
+  // the dev build of Vue is used. Avoid old browsers like IE11.
+  if (USE_DEVTOOLS && typeof Proxy !== 'undefined') {
     pinia.use(devtoolsPlugin)
   }
 
index 53538e8576cabfa8bec593721f1b279c0c9f2f4d..d54ffbbdfb9e21cba323ccd75b3329c19798669d 100644 (file)
@@ -1 +1,10 @@
 export const IS_CLIENT = typeof window !== 'undefined'
+
+/**
+ * Should we add the devtools plugins.
+ * - only if dev mode or forced through the prod devtools flag
+ * - not in test
+ * - only if window exists (could change in the future)
+ */
+export const USE_DEVTOOLS =
+  (__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__TEST__ && IS_CLIENT
index 2ff4d17a7c17fce0594fe9d412900dc9ee626f1a..03647fd61ed3b7c77e51936719745efdc66a39ec 100644 (file)
@@ -1,6 +1,6 @@
 import type { Plugin } from 'vue-demi'
 import { registerPiniaDevtools } from './devtools'
-import { IS_CLIENT } from './env'
+import { IS_CLIENT, USE_DEVTOOLS } from './env'
 import { Pinia, piniaSymbol, setActivePinia } from './rootStore'
 
 /**
@@ -56,9 +56,9 @@ export const PiniaVuePlugin: Plugin = function (_Vue) {
           // this allows calling useStore() outside of a component setup after
           // installing pinia's plugin
           setActivePinia(pinia)
-          if (__DEV__) {
-            registerPiniaDevtools(pinia._a, pinia)
-          }
+        }
+        if (USE_DEVTOOLS) {
+          registerPiniaDevtools(pinia._a, pinia)
         }
       } else if (!this.$pinia && options.parent && options.parent.$pinia) {
         this.$pinia = options.parent.$pinia
index 557f64995b9686be92c1d0c5781359b5256dfccc..c8ecfe0c81f90140ad8aedf8c29feec2e23e48ae 100644 (file)
@@ -173,6 +173,9 @@ function createReplacePlugin(
       (isBundlerESMBuild && !isRawESMBuild) || isNodeBuild
         ? `(process.env.NODE_ENV === 'test')`
         : 'false',
+    __FEATURE_PROD_DEVTOOLS__: isBundlerESMBuild
+      ? `__VUE_PROD_DEVTOOLS__`
+      : 'false',
     // If the build is expected to run directly in the browser (global / esm builds)
     __BROWSER__: JSON.stringify(isRawESMBuild),
     // is targeting bundlers?