Using store outside setup(), state persistence is not possible
Closed this issue · 1 comments
CCherry07 commented
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
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
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible of the bug.
semiaddict commented
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