From: Eduardo San Martin Morote Date: Wed, 17 Aug 2022 12:44:31 +0000 (+0200) Subject: fix(devtools): use flag to include devtools X-Git-Tag: @pinia/nuxt@0.4.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e92c360a4b4b8a39b2e3c284f31560120742b6f;p=thirdparty%2Fvuejs%2Fpinia.git fix(devtools): use flag to include devtools --- diff --git a/packages/pinia/src/createPinia.ts b/packages/pinia/src/createPinia.ts index 8279b4e9..f71497fd 100644 --- a/packages/pinia/src/createPinia.ts +++ b/packages/pinia/src/createPinia.ts @@ -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) } diff --git a/packages/pinia/src/env.ts b/packages/pinia/src/env.ts index 53538e85..d54ffbbd 100644 --- a/packages/pinia/src/env.ts +++ b/packages/pinia/src/env.ts @@ -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 diff --git a/packages/pinia/src/vue2-plugin.ts b/packages/pinia/src/vue2-plugin.ts index 2ff4d17a..03647fd6 100644 --- a/packages/pinia/src/vue2-plugin.ts +++ b/packages/pinia/src/vue2-plugin.ts @@ -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 diff --git a/rollup.config.js b/rollup.config.js index 557f6499..c8ecfe0c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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?