From: Rudy Date: Sat, 8 Oct 2022 18:06:01 +0000 (+0800) Subject: fix(store): init `_customProperties` for devtools (#1704) X-Git-Tag: @pinia/nuxt@0.4.3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c1dfce2e67c37e09251a7b85fcae2d6a4030fb8;p=thirdparty%2Fvuejs%2Fpinia.git fix(store): init `_customProperties` for devtools (#1704) Co-authored-by: Eduardo San Martin Morote --- diff --git a/packages/pinia/src/store.ts b/packages/pinia/src/store.ts index dec67e71..98d77a26 100644 --- a/packages/pinia/src/store.ts +++ b/packages/pinia/src/store.ts @@ -47,7 +47,7 @@ import { _StoreWithState, } from './types' import { setActivePinia, piniaSymbol, Pinia, activePinia } from './rootStore' -import { IS_CLIENT } from './env' +import { IS_CLIENT, USE_DEVTOOLS } from './env' import { patchObject } from './hmr' import { addSubscription, triggerSubscriptions, noop } from './subscriptions' @@ -455,18 +455,17 @@ function createSetupStore< } const store: Store = reactive( - assign( - __DEV__ && IS_CLIENT - ? // devtools custom properties + __DEV__ || USE_DEVTOOLS + ? assign( { - _customProperties: markRaw(new Set()), _hmrPayload, - } - : {}, - partialStore - // must be added later - // setupStore - ) + _customProperties: markRaw(new Set()), // devtools custom properties + }, + partialStore + // must be added later + // setupStore + ) + : partialStore ) as unknown as Store // store the partial store now so the setup of stores can instantiate each other before they are finished without @@ -662,7 +661,9 @@ function createSetupStore< store._getters = newStore._getters store._hotUpdating = false }) + } + if (USE_DEVTOOLS) { const nonEnumerable = { writable: true, configurable: true, @@ -670,17 +671,15 @@ function createSetupStore< enumerable: false, } - if (IS_CLIENT) { - // avoid listing internal properties in devtools - ;( - ['_p', '_hmrPayload', '_getters', '_customProperties'] as const - ).forEach((p) => { + // avoid listing internal properties in devtools + ;(['_p', '_hmrPayload', '_getters', '_customProperties'] as const).forEach( + (p) => { Object.defineProperty(store, p, { value: store[p], ...nonEnumerable, }) - }) - } + } + ) } /* istanbul ignore if */ @@ -692,7 +691,7 @@ function createSetupStore< // apply all plugins pinia._p.forEach((extender) => { /* istanbul ignore else */ - if (__DEV__ && IS_CLIENT) { + if (USE_DEVTOOLS) { const extensions = scope.run(() => extender({ store,