Skip to content

Commit 28eb0b2

Browse files
author
Guillaume Chau
committed
fix(vuex): stringify mutation payload in mutation history
1 parent 825d673 commit 28eb0b2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/backend/vuex.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ export function initVuexBackend (hook, bridge, isLegacy) {
140140
function addMutation (type, payload, options = {}) {
141141
const index = mutations.length
142142

143+
const payloadData = stringify(payload)
144+
143145
mutations.push({
144146
type,
145-
payload,
147+
payload: payloadData,
146148
index,
147149
handlers: store._mutations[type],
148150
registeredModules: Object.keys(registeredModules),
@@ -152,7 +154,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
152154
bridge.send('vuex:mutation', {
153155
mutation: {
154156
type: type,
155-
payload: stringify(payload),
157+
payload: payloadData,
156158
index
157159
},
158160
timestamp: Date.now()
@@ -294,15 +296,20 @@ export function initVuexBackend (hook, bridge, isLegacy) {
294296
if (!isProd) console.log('replay unregister module', path)
295297
} else if (mutation.handlers) {
296298
store._committing = true
297-
if (Array.isArray(mutation.handlers)) {
298-
mutation.handlers.forEach(handler => handler(mutation.payload))
299-
} else {
300-
if (isLegacy) {
301-
// Vuex 1
302-
mutation.handlers(store.state, mutation.payload)
299+
try {
300+
const payload = parse(mutation.payload, true)
301+
if (Array.isArray(mutation.handlers)) {
302+
mutation.handlers.forEach(handler => handler(payload))
303303
} else {
304-
mutation.handlers(mutation.payload)
304+
if (isLegacy) {
305+
// Vuex 1
306+
mutation.handlers(store.state, payload)
307+
} else {
308+
mutation.handlers(payload)
309+
}
305310
}
311+
} catch (e) {
312+
throw e
306313
}
307314
store._committing = false
308315
}

0 commit comments

Comments
 (0)