mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): allow serialising undefined refs (#20828)
This commit is contained in:
parent
2d07e491a4
commit
7f0fe2fbe7
@ -5,8 +5,8 @@ import { defineNuxtPlugin } from '#app/nuxt'
|
||||
|
||||
const revivers = {
|
||||
NuxtError: (data: any) => createError(data),
|
||||
EmptyShallowRef: (data: any) => shallowRef(JSON.parse(data)),
|
||||
EmptyRef: (data: any) => ref(JSON.parse(data)),
|
||||
EmptyShallowRef: (data: any) => shallowRef(data === '_' ? undefined : JSON.parse(data)),
|
||||
EmptyRef: (data: any) => ref(data === '_' ? undefined : JSON.parse(data)),
|
||||
ShallowRef: (data: any) => shallowRef(data),
|
||||
ShallowReactive: (data: any) => shallowReactive(data),
|
||||
Ref: (data: any) => ref(data),
|
||||
|
@ -6,8 +6,8 @@ import { defineNuxtPlugin } from '#app/nuxt'
|
||||
|
||||
const reducers = {
|
||||
NuxtError: (data: any) => isNuxtError(data) && data.toJSON(),
|
||||
EmptyShallowRef: (data: any) => isRef(data) && isShallow(data) && !data.value && JSON.stringify(data.value),
|
||||
EmptyRef: (data: any) => isRef(data) && !data.value && JSON.stringify(data.value),
|
||||
EmptyShallowRef: (data: any) => isRef(data) && isShallow(data) && !data.value && (JSON.stringify(data.value) || '_'),
|
||||
EmptyRef: (data: any) => isRef(data) && !data.value && (JSON.stringify(data.value) || '_'),
|
||||
ShallowRef: (data: any) => isRef(data) && isShallow(data) && data.value,
|
||||
ShallowReactive: (data: any) => isReactive(data) && isShallow(data) && toRaw(data),
|
||||
Ref: (data: any) => isRef(data) && data.value,
|
||||
|
@ -380,6 +380,7 @@ describe('rich payloads', () => {
|
||||
'Recursive objects: true',
|
||||
'Shallow reactive: true',
|
||||
'Shallow ref: true',
|
||||
'Undefined ref: true',
|
||||
'Reactive: true',
|
||||
'Ref: true',
|
||||
'Error: true'
|
||||
|
2
test/fixtures/basic/pages/json-payload.vue
vendored
2
test/fixtures/basic/pages/json-payload.vue
vendored
@ -6,6 +6,7 @@ if (process.server) {
|
||||
state.value.ref = r
|
||||
state.value.shallowReactive = shallowReactive({ nested: { ref: r } })
|
||||
state.value.shallowRef = shallowRef(false)
|
||||
state.value.undefined = shallowRef()
|
||||
state.value.reactive = reactive({ ref: r })
|
||||
state.value.error = createError({ message: 'error' })
|
||||
state.value.date = new Date()
|
||||
@ -19,6 +20,7 @@ if (process.server) {
|
||||
Error: {{ isNuxtError(state.error) }} <hr>
|
||||
Shallow reactive: {{ isReactive(state.shallowReactive) && isShallow(state.shallowReactive) }} <br>
|
||||
Shallow ref: {{ isShallow(state.shallowRef) }} <br>
|
||||
Undefined ref: {{ isRef(state.undefined) }} <br>
|
||||
Reactive: {{ isReactive(state.reactive) }} <br>
|
||||
Ref: {{ isRef(state.ref) }} <hr>
|
||||
Recursive objects: {{ state.ref === state.shallowReactive.nested.ref }} <br>
|
||||
|
Loading…
Reference in New Issue
Block a user