]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(ssr): delay getters read
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Jul 2021 13:32:43 +0000 (15:32 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 09:52:25 +0000 (11:52 +0200)
src/store.ts

index 3e15d7c9efd9700454178164d527e558b23af1fb..eee31cd7ec254263cd0f2f5c083bf706c5914b7c 100644 (file)
@@ -93,6 +93,8 @@ function createOptionsStore<
 
   const initialState: StateTree | undefined = pinia.state.value[id]
 
+  let store: Store<Id, S, G, A>
+
   function setup() {
     if (!initialState && (!__DEV__ || !hot)) {
       $reset()
@@ -112,14 +114,14 @@ function createOptionsStore<
         computedGetters[name] = computed(() => {
           setActivePinia(pinia)
           // @ts-expect-error
-          return getters![name].call(store, store)
+          return store && getters![name].call(store, store)
         })
         return computedGetters
       }, {} as Record<string, ComputedRef>)
     )
   }
 
-  const store = createSetupStore(id, setup, options, hot)
+  store = createSetupStore(id, setup, options, hot)
 
   // TODO: HMR should also replace getters here
 
@@ -371,6 +373,7 @@ function createSetupStore<
   })
 
   // overwrite existing actions to support $onAction
+  scope.off()
   for (const key in setupStore) {
     const prop = setupStore[key]
 
@@ -417,6 +420,7 @@ function createSetupStore<
       }
     }
   }
+  scope.on()
 
   const partialStore = {
     _p: pinia,
@@ -494,6 +498,7 @@ function createSetupStore<
           wrapAction(actionName, action)
       }
 
+      // TODO: does this work in both setup and option store?
       for (const getterName in newStore._hmrPayload.getters) {
         const getter: _Method = newStore._hmrPayload.getters[getterName]
         // @ts-expect-error