-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renderJsonPayloads causes Cannot stringify arbitrary non-POJOs error #21060
Comments
If I can add a detail: it's happening when trying to set a class instance as a In the provided starter: const foo = ref<Foo>(new Foo()); triggers the error while: const foo = ref<Foo>({foo: 'foo'}); is ok. |
Yes, that would be the case. You should define a custom payload reviver/reducer if you want to include a custom class in anything that is serialised (passed from server -> client), which would include store data. See example here: https://nuxt.com/docs/api/composables/use-nuxt-app#payload. |
@danielroe sorry for the ping, but could you please consider expanding upon the documentation for the I have a ton of questions like:
Let's say I have a method which returns an array of the constructor parameters. Would this be the correct way of registering the payload plugin? export default definePayloadPlugin(() => {
definePayloadReducer('ApiResponse', data => data instanceof ApiResponse && data.getReducedData())
// @ts-ignore (bcs data is typed as string for some reason)
definePayloadReviver('ApiResponse', data => new ApiResponse(...data))
}) I know that you showed this in one of your twitch streams, but I wasn't able to find it. |
@CernyMatej Let's do that here: #21832 |
This document makes people dizzy, and I can't understand what I need to do to work properly. |
if you comment on the linked issue for adding better docs (#21832) with what you find confusing, specifically, and perhaps what you've tried and hasn't worked, we can make sure to address it when we write them. |
Environment
Reproduction
https://stackblitz.com/edit/nuxt-3-h3gq8x?file=composables%2FuseFooStore.ts
Describe the bug
Same as #20787. When
renderJsonPayloads
is set totrue
, this error occures:renderJsonPayloads causes Cannot stringify arbitrary non-POJOs
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: