prazdevs / pinia-plugin-persistedstate

💾 Configurable persistence and rehydration of Pinia stores.
https://prazdevs.github.io/pinia-plugin-persistedstate/
MIT License
2.13k stars 121 forks source link

Using store outside setup(), state persistence is not possible #294

Closed CCherry07 closed 1 month ago

CCherry07 commented 7 months ago

Describe the bug

code :


import { createPinia, defineStore } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
// config ->  {  persist: true }
export const createStore = <T>(storeId: string, defineSetup: () => T, config?: unknown) => {
  return () => defineStore(storeId, defineSetup, config)(pinia)
}

Reproduction

https://stackblitz.com/edit/vitejs-vite-6fthbm?file=package.json,src%2FApp.vue,src%2Fstore%2FuseCount.ts,vite.config.ts

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 183.73 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
    pnpm: 8.13.1 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.87
    Edge: 123.0.2420.65
    Safari: 17.4.1

Used Package Manager

pnpm

Validations

semiaddict commented 7 months ago

Hi, I seem to be experiencing a similar issue when using pinia globally via setActivePinia for web components. Here's a repro: https://stackblitz.com/edit/vitejs-vite-7fdisv?file=src%2Fmain.ts