From 2f3bd5330e853b8ef11b6364a3a86e780c5f309f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 16 Jul 2021 15:32:43 +0200 Subject: [PATCH] fix(ssr): delay getters read --- src/store.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/store.ts b/src/store.ts index 3e15d7c9..eee31cd7 100644 --- a/src/store.ts +++ b/src/store.ts @@ -93,6 +93,8 @@ function createOptionsStore< const initialState: StateTree | undefined = pinia.state.value[id] + let store: Store + 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) ) } - 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 -- 2.47.2