strapi / blocks-react-renderer

A React renderer for the Strapi's Blocks rich text editor
Other
107 stars 15 forks source link

[bug]: Cannot render in server component context #31

Open AndreasBBS opened 3 months ago

AndreasBBS commented 3 months ago

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.