-
Notifications
You must be signed in to change notification settings - Fork 26
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
[bug]: Cannot render in server component context #31
Comments
@remidej Can I introduce a merge request with my proposed solution for this or do you think there's another way that's more proper? I've been waiting for some feedback on my propose solution to initiate a pull request. |
@AndreasBBS Can you please share your solution? I am trying to render the BlocksRenderer inside a Server component and I get a different error, but this might help me aswell. |
This workaround is working for me. But be warned that this forces you to send the content of the BlocksRenderer to the frontend where a sophisticated actor might capture it so make sure nothing sensitive or secret goes there. |
Thank you for sharing. I ended up downloading the source files, so I can change what I want. I am using NextJS with BlocksRenderer inside some server-side pages which are actually prerendered as static HTML during builds, so I'm not sure I understand your issue. Just a suggestion, I don't know if it applies but it might be worth using an email service such as Brevo instead of nodemailer and sending custom emails from there :) |
Rendering a BlocksRenderer inside a server component should not be a problem because it is marked as |
What version of
@strapi/blocks-react-renderer
are you using?npm: 9.8.1
node: 20.9.0
react: 18.2.0
next: 14.1.4
@strapi/blocks-react-renderer: 1.0.1
browser: any
What's Wrong?
I have a use case where I need to send the HTML on nodemailer. Strapi sends the result as JSON so I'm getting the HTML by using
renderToStaticMarkup(<BlocksRenderer content={blocks}/>)
.Unfortunately when I do this in Next 14 in a server action it throws an error.
To Reproduce
I made this codesandbox with a reproduction of the bug
Expected Behaviour
I expect to be able to render the BlocksRenderer component in the context of the server so that I can in turn use it to render the static markup.
I suspect that it has to do with the fact that BlocksRenderer has 'use client' and so Next 14 is probably skipping rendering in the context of the server. I don't wish to introduce a breaking change so I suggest making something like BlocksRendererPure without the 'use client' and the current BlocksRenderer expose as the BlocksRendererPure wrapped in a wrapper with the 'use client'.
If help is needed for a merge request let me know and I'll submit a fix according to whatever the package owner decides is the best way to fix this.
The text was updated successfully, but these errors were encountered: