Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

fix: 1373 storyblokrichtext blok resolver not working #1388

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

alvarosabu
Copy link
Contributor

  • Introduced new components for server-side rich text rendering.
  • Updated existing components and pages to utilize the new rich text features.
  • Enhanced the layout and styling of the playground for better user experience.
  • Update Next.js playground with Tailwind CSS and rich text enhancements
  • Added Tailwind CSS dependencies for styling.

- Added new custom blok to test
- Added tailwindcss for styling
- Introduced new components for server-side rich text rendering.
- Updated existing components and pages to utilize the new rich text features.
- Enhanced the layout and styling of the playground for better user experience.
- Update Next.js playground with Tailwind CSS and rich text enhancements
- Added Tailwind CSS dependencies for styling.
- Added a missing semicolon to the `@apply m-0` rule for emoji images in `globals.css` and `styles.css` to ensure proper CSS parsing.
- Removed an unused import of `EmojiRandomizer` in `page.tsx` to clean up the codebase.
@alvarosabu alvarosabu added the bugfix [PR] Fixes a bug label Mar 27, 2025
@alvarosabu alvarosabu requested a review from edodusi March 27, 2025 08:42
Copy link

pkg-pr-new bot commented Mar 27, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@storyblok/react@1388

commit: 66c948c

<StoryblokServerRichText doc={story.content.richText} />
</div>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this example we are using the rsc module which is meant for Next.js App Router, but the code does not reflect the changes in the DX (they are documented in the README).

So either we change the example detailing that this is for App Router and reuse the same code, or we document that this is a non-strict example that only details how to use the StoryblokServerRichText component but everything else needs to be adapted to the user's context.

Or you can have more control by using the `useStoryblokServerRichText` hook:

```ts
import { useStoryblokServerRichText, convertAttributesInElement } from '@storyblok/react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are them not exported from the rsc module?

export function componentResolver(node: StoryblokRichTextNode<React.ReactElement>): React.ReactElement {
const body = node?.attrs?.body;
return React.createElement(StoryblokServerComponent, {
blok: Array.isArray(body) ? body[0] : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could still be an empty array

Suggested change
blok: Array.isArray(body) ? body[0] : undefined,
blok: Array.isArray(body) && body.length > 0 ? body[0] : undefined,

const body = node?.attrs?.body;
return React.createElement(StoryblokServerComponent, {
blok: Array.isArray(body) ? body[0] : undefined,
key: node.attrs?.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk of an undefined key

Suggested change
key: node.attrs?.id,
key: node.attrs?.id || `storyblok-component-${Date.now()}`,

...options.resolvers,
},
keyedResolvers: true,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the other options? You are only using options.resolvers instead of merging the whole options parameter

import { useStoryblokServerRichText } from './server-richtext';

const StoryblokRichText = forwardRef<HTMLDivElement, StoryblokRichTextProps>(
({ doc, resolvers }, ref) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to return immediately if we don't have the doc, something like

    if (!doc) {
      return null;
    }

@franzi-wtfoxtrot
Copy link

Hey @alvarosabu , is there any chance to get this PR merged? We´re looking forward to use the RTR in our React 19/Next.js 15 Project :)

@alvarosabu
Copy link
Contributor Author

Hi @franzi-wtfoxtrot we are currently focusing on the stable release of the CLI v4 storyblok/storyblok-cli#181 but I already saved some capacity in the following weeks to tackle this. Hopefully, we can have it soon. Thanks for the patience 🙏🏻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix [PR] Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants