Skip to content
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

Richtext Resolver - accept React components #1290

Open
1 task done
kylehotchkiss opened this issue Dec 13, 2024 · 1 comment
Open
1 task done

Richtext Resolver - accept React components #1290

kylehotchkiss opened this issue Dec 13, 2024 · 1 comment
Labels
pending-author [Issue] Awaiting further information or action from the issue author

Comments

@kylehotchkiss
Copy link

kylehotchkiss commented Dec 13, 2024

Description

Currently (or as I understand it), the richText resolver only supports static HTML strings as input. This makes the WYSIWYG blocks less functional than they could be for several reasons:

  1. Tailwind, a fairly common CSS framework, doesn't extrapolate classnames out of HTML strings
  2. ReactDOM stringify functions are not available for use within Next.js rendered pages,
  3. ReactDOM can be dynamically imported as a workaround, but the resolver cannot support async callbacks

Suggested solution or improvement

Accept react components as children in the richText resolver

Additional context

Roughly I'd like to be able to do either of the following:

    resolver: async (component, blok) => {
      switch (component) {
        case 'quote':
          return (<div>Test</div>)
        case 'relatedPosts':
          const { renderToStaticMarkup } = await import('react-dom/server');
          return renderToStaticMarkup(createElement(RelatedPosts));
        default:
          return 'Resolver not defined'
      }
    },
  }

Validations

@kylehotchkiss kylehotchkiss added pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Dec 13, 2024
@edodusi edodusi removed the pending-triage [Issue] Ticket is pending to be prioritised label Dec 17, 2024
@edodusi
Copy link
Contributor

edodusi commented Dec 17, 2024

hi @kylehotchkiss, in version 4.3.0 we added a new RichText component that supports React components, can you try it and give us feedback?

Here's the link to some documentation about it https://github.com/storyblok/storyblok-react#overriding-the-default-resolvers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-author [Issue] Awaiting further information or action from the issue author
Projects
None yet
Development

No branches or pull requests

2 participants