Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Integration of pinia into vike-vue.
See vikejs/vike#1374
I decided to follow the other repositories and create a
package
folder for this. We should probably move the existing code into that folder as well, but for now I let it be so as not to have too many changes.I'd appreciate general feedback on my approach here - is having new hooks the way to go here? Is it ok to provide a default
onCreateApp
hook here and expect the user to provide their own, while importing the one from this package like in the example+onCreateApp.ts
?I do have one issue with this implementation - other stores / data fetching tools like tan-query need to hook into the same place, which becomes unwieldy. So my solution would be to make the hooks I introduced more general - maybe call them
onAfterRenderSSRApp
(dehydrate) andonBeforeMountApp
(hydrate) or something. But then I run into two issues - firstly,onAfterRenderSSRApp
would have to return an object that we add to thepageContext
thatonRenderHtml
returns, as we need to leave it up to the package what the property is called that will be sent to the client, otherwise we need to include it invike-vue
'spassToClient
. That would, however, expose another low-level hook that can be used to directly set properties onpageContext
. Secondly, we don't want to exclude users from using multiple state management libraries. I for myself use both pinia and vue-query. If they both use the aforementioned hooks, we'd need some way of orchestrating that or go and make this a proper pub / sub where any function can register to get notified by these hooks. In general I think it would be very beneficial if we don't have to touchvike-vue
's base package for any other state management tool, as no normal user can do this, thus preventing any packages outside of this repository to be implemented in the same way.I hope this is written in a way that's not too confusing.
Also I'll try to write some tests when I find the time.