Skip to content

Commit 709ed3b

Browse files
committed
fix(devtools): preserve store reactivity
1 parent 8dc5622 commit 709ed3b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: packages/pinia/src/devtools/actions.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ export async function actionGlobalCopyState(pinia: Pinia) {
4747
export async function actionGlobalPasteState(pinia: Pinia) {
4848
if (checkClipboardAccess()) return
4949
try {
50-
Object.assign(
51-
pinia.state.value,
52-
JSON.parse(await navigator.clipboard.readText())
53-
)
50+
loadStoresState(pinia, JSON.parse(await navigator.clipboard.readText()))
5451
toastMessage('Global state pasted from clipboard.')
5552
} catch (error) {
5653
if (checkNotFocusedError(error)) return
@@ -111,7 +108,7 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
111108
const result = await open()
112109
if (!result) return
113110
const { text, file } = result
114-
Object.assign(pinia.state.value, JSON.parse(text))
111+
loadStoresState(pinia, JSON.parse(text))
115112
toastMessage(`Global state imported from "${file.name}".`)
116113
} catch (error) {
117114
toastMessage(
@@ -121,3 +118,12 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
121118
console.error(error)
122119
}
123120
}
121+
122+
function loadStoresState(pinia: Pinia, state: Record<string, unknown>) {
123+
for (const key in state) {
124+
const storeState = pinia.state.value[key]
125+
if (storeState) {
126+
Object.assign(storeState, state[key])
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)