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

feat: use Contentful.EntryFields.RichText #106

Merged
merged 4 commits into from
Mar 13, 2023

Conversation

AndrewLeedham
Copy link
Contributor

@AndrewLeedham AndrewLeedham commented Mar 3, 2021

fixes: #10

Replaces CFRichTextTypes.Block | CFRichTextTypes.Inline with Contentful.EntryFields.RichText,

Copy link
Collaborator

@marcolink marcolink left a comment

Choose a reason for hiding this comment

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

Hi @AndrewLeedham, thanks again :)

I just have a little comment.

src/cf-definitions-builder.ts Outdated Show resolved Hide resolved
@AndrewLeedham AndrewLeedham marked this pull request as ready for review March 3, 2021 23:16
@AndrewLeedham AndrewLeedham requested a review from marcolink March 3, 2021 23:16
@AndrewLeedham
Copy link
Contributor Author

@marcolink it seems that Contentful.EntryFields.RichText is not compatible with the type Document from @contentful/rich-text-types. It is throwing the following error:

image

This is occurring when using: https://github.com/contentful/rich-text/tree/master/packages/rich-text-react-renderer

So I am wondering which of the following is the best course of action:

  1. Update the contentful.js RichText type to use @contentful/rich-text-types.
  2. Update @contentful/rich-text-react-renderer to accept both types e.g string and enum.
  3. Switch to using CFRichTextTypes.Document here.

@marcolink
Copy link
Collaborator

marcolink commented Mar 4, 2021

Hi @AndrewLeedham,
I feel this should be directly addressed in contentful.js. If you want - pull requests are always welcome :)

If the only incompatibility is the enum vs string problem, I wonder if a fix in @contentful/rich-text-react-renderer would be the better solution 🤔

@AndrewLeedham
Copy link
Contributor Author

If the only incompatibility is the enum vs string problem

This playground link illustrates the issue.

I wonder if a fix in @contentful/rich-text-react-renderer would be the better solution 🤔

That would require using a union instead of an enum, which I think would be worse IMO (also a fairly big breaking change). Given @contentful/rich-text-react-renderer is already centralised, requiring it and relying on it in contentful.js makes the most sense to me?

@marcolink
Copy link
Collaborator

Hey @AndrewLeedham,

I'll discuss it next week, hopefully, I can post an update on it next week 🤞

@mbifulco
Copy link

Hi team - bumping an old issue here (sorry!) to see if there was a resolution to this discussion.

I've been using cf-content-types-generator in my project, and I'm looking for the right/accepted/recommended way to use @contentful/rich-text-react-renderer's documentToReactComponents with the types generated by this library.

If I use the types as generated, I get the following TypeScript error:

Argument of type 'Block | Inline' is not assignable to parameter of type 'Document'.

I tried manually changing the type on rich text fields to Contentful.EntryFields.RichText as well - ultimately I've had the best results so far if I cast the field I'm trying to render to a Document:

import { Document } from "@contentful/rich-text-types";

// ...

documentToReactComponents(inputField as Document, options);

I'm sure I'm missing something simple here, and would love some help!

@AndrewLeedham
Copy link
Contributor Author

@mbifulco @marcolink updated this PR for the latest code based changes 👍

@marcolink
Copy link
Collaborator

Thanks @AndrewLeedham,
I think this is the right way for now 👍

@marcolink marcolink merged commit 769320d into contentful-userland:master Mar 13, 2023
@github-actions
Copy link

🎉 This PR is included in version 2.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mbifulco
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove @contentful/rich-text-types dependency in output
3 participants