From e7c7815bcf10691b986a0a4495a5c98258dede27 Mon Sep 17 00:00:00 2001 From: prazdevs <1631886+prazdevs@users.noreply.github.com> Date: Sun, 16 Jul 2023 17:03:00 +0200 Subject: [PATCH] :recycle: refactor hmr related code --- packages/plugin/src/plugin.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/plugin/src/plugin.ts b/packages/plugin/src/plugin.ts index 27d3b78..06ec5cf 100644 --- a/packages/plugin/src/plugin.ts +++ b/packages/plugin/src/plugin.ts @@ -69,22 +69,17 @@ export function createPersistedState( if (!persist) return - // if store is created when hmr, it will not be put in `pinia.state`. - // see https://github.com/vuejs/pinia/blob/v2/packages/pinia/src/store.ts#L265-L272. - /** is original store or hot store */ - const is_original = store.$id in pinia.state.value - // if store is created as hot store, we're support to do nothing. - /* c8 ignore next 3 */ - if (!is_original) { - const original_id = store.$id.replace('__hot:', '') + + // HMR handling, ignores stores created as "hot" stores + /* c8 ignore start */ + if (!(store.$id in pinia.state.value)) { // @ts-expect-error `_s is a stripped @internal` - const original_store = pinia._s.get(original_id) - /* c8 ignore next 3 */ + const original_store = pinia._s.get(store.$id.replace('__hot:', '')) if (original_store) - // `$persist` original_store after anything finished Promise.resolve().then(() => original_store.$persist()) return } + /* c8 ignore stop */ const persistences = ( Array.isArray(persist)