From: Eduardo San Martin Morote Date: Wed, 28 Jul 2021 10:05:23 +0000 (+0200) Subject: fix(devtools): avoid redundant timeline event with hmr X-Git-Tag: v2.0.0-rc.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5de4d3e27c0bc1b6885698692380da5a6e2745fa;p=thirdparty%2Fvuejs%2Fpinia.git fix(devtools): avoid redundant timeline event with hmr --- diff --git a/src/store.ts b/src/store.ts index dfe3ff88..6c0d1d1b 100644 --- a/src/store.ts +++ b/src/store.ts @@ -171,7 +171,7 @@ function createSetupStore< if (isListening) { debuggerEvents = event // avoid triggering this while the store is being built and the state is being set in pinia - } else if (isListening == false) { + } else if (isListening == false && !store._hotUpdating) { // let patch send all the events together later /* istanbul ignore else */ if (Array.isArray(debuggerEvents)) { @@ -434,6 +434,7 @@ function createSetupStore< // add the hotUpdate before plugins to allow them to override it if (__DEV__) { store._hotUpdate = markRaw((newStore) => { + store._hotUpdating = true newStore._hmrPayload.state.forEach((stateKey) => { if (stateKey in store.$state) { const newStateTarget = newStore.$state[stateKey] @@ -462,7 +463,10 @@ function createSetupStore< } }) + // avoid devtools logging this as a mutation + isListening = false pinia.state.value[$id] = toRef(newStore._hmrPayload, 'hotState') + isListening = true for (const actionName in newStore._hmrPayload.actions) { const action: _Method = newStore[actionName] @@ -505,6 +509,7 @@ function createSetupStore< // update the values used in devtools and to allow deleting new properties later on store._hmrPayload = newStore._hmrPayload store._getters = newStore._getters + store._hotUpdating = false }) const nonEnumerable = { diff --git a/src/types.ts b/src/types.ts index 1a4593cf..c552a372 100644 --- a/src/types.ts +++ b/src/types.ts @@ -265,6 +265,14 @@ export interface StoreProperties { */ _hotUpdate(useStore: StoreGeneric): void + /** + * Allows pausing some of the watching mechanisms while the store is being + * patched with a newer version. + * + * @internal + */ + _hotUpdating: boolean + /** * Payload of the hmr update. Dev only. * @@ -469,12 +477,7 @@ export interface StoreDefinition< * @param pinia - Pinia instance to retrieve the store * @param hot - dev only hot module replacement */ - (pinia?: Pinia | null | undefined, hot?: Store): Store< - Id, - S, - G, - A - > + (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store /** * Id of the store. Used by map helpers.