sanity-io / block-content-to-hyperscript

Function for transforming Sanity block content to HyperScript
MIT License
17 stars 8 forks source link

Duplicate List Items #15

Open rothnic opened 4 years ago

rothnic commented 4 years ago

If you have a simple block with a bulleted list, where the list has a single list item in it, I get a duplicate list item.

<ul>
    <li></li>
</ul>
<li></li>

Instead of:

<ul>
    <li></li>
</ul>
rothnic commented 4 years ago

I'm using this with svelte-portable-text.

It turns out that if I manually set renderContainerOnSingleChild in block-content-to-hyperscript/lib/blocksToNodes.js, then it fixes my issue.

svelte-portable-text doesn't seem to pass the option along if I set it. However, I'm not sure if the core issue of rendering the element twice is a problem of this library or the svelte library.

rothnic commented 4 years ago

Another update. I'm using the svelte/sapper blog starter with sanity. I am able to configure renderContainerOnSingleChild by adding it as a property here in svelte-portable-text.

I then have a line in the blog starter like this:

<BlockContent blocks={myObject.body} {serializers} renderContainerOnSingleChild={true} />

With this statement, I no longer have the duplicates. Swapping renderContainerOnSingleChild={true} for renderContainerOnSingleChild={false} will bring the issue back.

So, my question would be, should this setting be required to not run into this duplicate text list item issue?