sanity-io / block-content-to-react

Deprecated in favor of @portabletext/react
https://github.com/portabletext/react-portabletext
MIT License
161 stars 25 forks source link

Output wrapped in an empty div container #42

Closed leonardoanalista closed 3 years ago

leonardoanalista commented 3 years ago

The default container is a div. This creates an empty div that wrapping every element rendered. Sometimes we have invalid HTML markup because the contents are rendered inside a Heading tag. Heading tag can only contain inline elements: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content

Validator used: https://validator.w3.org/nu

Here is the code: https://github.com/sanity-io/block-content-to-hyperscript/blob/d9d5adac36d50c0c012f7bb4099fb6f3fa67b382/src/serializers.js#L156

Should the default container value be just a Fragment for React apps?

I know we can just set the container prop to a Fragment. I am wondering if there are any other implications I am unable to see?

xiata commented 3 years ago

You can do this by <BlockContent serializers={{ container: ({ children }) => children, /* your types defs, etc */ }} />

I already do this with significantly more complicated logic.