Open kabalage opened 2 weeks ago
This should be doable with a payload plugin that turns marked properties into into undefined or any other value
BTW, you can (and should)use that for complex state. I go into all the details in my mastering pinia course
I think I just did that. I created a wrapper called skipSerialize()
, in which I used a Symbol
to mark the object similarly to how skipHydrate
does it, and then I used definePayloadPlugin()
to take control of its serialization.
Would it be beneficial to include this (or something similar) in the core library, or would you prefer to keep it separate? I could set up a PR if you're interested.
Edit: Yeah I agree that this is not something you want to do often, but we need it in a particularly complex part of our app.
We can reuse the skipHydrate. The data was unused anyway. I pushed to feat/nuxt-skip-hydrate-in-payload if you want to give it a try. For some reason the payload plugin is not being applied.
I'll give it a try maybe tomorrow. I glanced trough the code quickly, and the problem might be that you need to return a truthy value in the reducer to make it count as a match.
definePayloadReducer(
'skipHydrate',
(data: unknown) => !shouldHydrate(data) && 1
)
What problem is this solving
I expected that
skipHydrate
would also leave the ref out of the Nuxt payload. Nuxt throws errors when it cannot serialize certain objects. I could keep unserializable stuff out of the pinia stores, but I don't like the idea of introducing multiple solutions for shared state. I would much prefer to use Pinia for all shared state.Example CodeSandbox
Proposed solution
Make
skipHydrate
also skip transferring of values to the nuxt payload.Describe alternatives you've considered
No response