-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: support React Server Components and Next app router #1201
Conversation
f475f63
to
73ad620
Compare
eeaaa6a
to
a120768
Compare
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will continue checking, this is only the review for this commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few commments from my side Edo!
BREAKING CHANGE: components renamed and `storyblokInit` returns the API instance
c5971a8
to
5d2b50b
Compare
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This proposal aims to solve #952 by reorganizing the exports that we have in our
react/rsc
module and making a slightly impactful change on thestoryblokInit()
function.By copying the
StoryblokComponent
andStory
components in thersc
module we are creating a boundary between thersc
and the rest, ensuring proper isolation. Ideally we don't want to have duplicated code and this would need some refactoring in the future.The most significant change is in the
storyblokInit()
function, which now instead of just setting the globalstoryblokApi
variable is returning it. This is because if we rely on side effects only foruseStoryblokApi()
we may fall into race conditions, especially in RSC where the context is not shared between client and server and we don't have a state, every new component is rendered from scratch andstoryblokApi
could be uninitialized.So for every new render, client or server, if we have the
storyblokApi
initialized then we can return it, otherwise we need a new server side call to initialize it.This results in a small change for the clients implementing this SDK:
storyblokInit()
now returns the API object that components need to fetch data.Here's an example of a client implementation.
And in components:
This should not affect existing implementations. Follow the updated README for the rest of the implementation.
This would require to update the documentation on the RSC part.