Skip to content

Commit

Permalink
♻️ refactor hmr related code
Browse files Browse the repository at this point in the history
  • Loading branch information
prazdevs committed Jul 16, 2023
1 parent 43df15e commit e7c7815
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e7c7815

Please sign in to comment.