]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(devtools): avoid redundant timeline event with hmr
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 28 Jul 2021 10:05:23 +0000 (12:05 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 28 Jul 2021 10:05:23 +0000 (12:05 +0200)
src/store.ts
src/types.ts

index dfe3ff8811679e1540002f78d41388c307b5381f..6c0d1d1b26267d8c8bca8e61213ae5c5275c33dd 100644 (file)
@@ -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 = {
index 1a4593cfbbb4954a04d38e406d225156a0101987..c552a372c96ebe94a47108f5cdd5b815f08e2ef8 100644 (file)
@@ -265,6 +265,14 @@ export interface StoreProperties<Id extends string> {
    */
   _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<Id, S, G, A>): Store<
-    Id,
-    S,
-    G,
-    A
-  >
+  (pinia?: Pinia | null | undefined, hot?: StoreGeneric): Store<Id, S, G, A>
 
   /**
    * Id of the store. Used by map helpers.