Extending StoryblokComponent with pageData prop for context passing #1253
Labels
dx
[Issue] Improvement or fix with impact on the developer experience.
has-workaround
[Issue] Temporary solutions available.
p2-nice-to-have
[Priority] Lower priority, beneficial enhancements that are not urgent.
pending-author
[Issue] Awaiting further information or action from the issue author
pending-triage
[Issue] Ticket is pending to be prioritised
Description
Context / Problem
As we know, NextJS does not have native data passing mechanism from server to server component (something like Astro has
Astro.locals
, which is available in components, middleware and endpoints), hence we can only use prop-drilling in NextJS.Here is a quick comparison of the mechanisms available in Astro vs NextJS:
NextJS has reasons for not having this, and it's due to segmentation (explained here vercel/next.js#43704 (comment)). For the same reasons, you can't access the URL / Pathname information in server components.
Suggested solution or improvement
Workaround with Storyblok approach
However, not having the possibility to pass data server-to-server can be a challenge, there is a pattern how can we overcome this, and here is how?
There might be users who want to implement the following use cases (just a few examples):
[...slug]/page.tsx
), resolve the "locale" for the page and pass it down to Storyblok components so they can react to it, hence pre-render language switcher choices according to business logic.The pattern we use is to always pass
pageData
prop to StoryblokComponent:So we always know that the other component has access to that contextual data. The only thing is that developers should not forget to pass that data down each time in component implementation - this might have the potential to be enforced by wrapping StoryblokComponent with custom logic and using it, or the component in this SDK could do so.
Closing remarks
This may not necessarily be something to implement or do in the code, as it is possible to implement in projects even now, because StoryblokComponent implementation allows us to pass any rest props down to components, but I am sure this pattern could be outlined somewhere in the documentation of the SDK as an example of how to achieve one or the other sophisticated pattern.
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: