Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): experimental option for rich json payloads (#19205)
Co-authored-by: Daniel Roe <daniel@roe.dev>
- Loading branch information
Showing
24 changed files
with
355 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { reactive, ref, shallowRef, shallowReactive } from 'vue' | ||
import { definePayloadReviver, getNuxtClientPayload } from '#app/composables/payload' | ||
import { createError } from '#app/composables/error' | ||
import { callWithNuxt, 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)), | ||
ShallowRef: (data: any) => shallowRef(data), | ||
ShallowReactive: (data: any) => shallowReactive(data), | ||
Ref: (data: any) => ref(data), | ||
Reactive: (data: any) => reactive(data) | ||
} | ||
|
||
export default defineNuxtPlugin(async (nuxtApp) => { | ||
for (const reviver in revivers) { | ||
definePayloadReviver(reviver, revivers[reviver as keyof typeof revivers]) | ||
} | ||
Object.assign(nuxtApp.payload, await callWithNuxt(nuxtApp, getNuxtClientPayload, [])) | ||
// For backwards compatibility - TODO: remove later | ||
window.__NUXT__ = nuxtApp.payload | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { isShallow, isRef, isReactive, toRaw } from 'vue' | ||
import { definePayloadReducer } from '#app/composables/payload' | ||
import { isNuxtError } from '#app/composables/error' | ||
import { defineNuxtPlugin } from '#app/nuxt' | ||
/* Defining a plugin that will be used by the Nuxt framework. */ | ||
|
||
const reducers = { | ||
NuxtError: (data: any) => isNuxtError(data) && data.toJSON(), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pi0
Author
Member
|
||
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, | ||
Reactive: (data: any) => isReactive(data) && toRaw(data) | ||
} | ||
|
||
export default defineNuxtPlugin(() => { | ||
for (const reducer in reducers) { | ||
definePayloadReducer(reducer, reducers[reducer as keyof typeof reducers]) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Hi @pi0 is it possible to desactivate this line ?
I'm using
constructor: { __h3_error__: true }
because I need to have a response api error and not a custom error manage in h3.Example: My Api send an array of object error to show in FrontEnd the error, so this line
data.toJSON()
doesn't work because my data is an object and not anEvent
Do you have a solution for me ?