From: Eduardo San Martin Morote Date: Fri, 16 Jul 2021 13:32:43 +0000 (+0200) Subject: fix(ssr): delay getters read X-Git-Tag: v2.0.0-rc.0~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f3bd5330e853b8ef11b6364a3a86e780c5f309f;p=thirdparty%2Fvuejs%2Fpinia.git fix(ssr): delay getters read --- 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