Skip to content

HTML custom block is making a weird behavior during render #35

@jericho-forte

Description

@jericho-forte

I'm using datocms-structured-text-to-html-string and I have inserted a custom block (HTML block with a table inside) but for some reason it is rendering twice and the second one has incorrect tags when it should it only render once. Can anyone help or point out if I'm doing something wrong?

Here is the code snippet:

  const options = {
    renderBlock({ record, adapter: { renderNode } }: any) {
      return renderNode(record.table);
    },
  };

  const raw = useMemo(
    () => render(content[translation], options) as string,
    [content, translation]
  );

return ( 
  <div
      dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(raw) }}
    />
)

record.table contains when I log it to the console:

<table border="1" style="border-collapse: collapse;">
<tbody>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
<tr>
<td>Hello 1</td>
<td>Hello 2</td>
<td>Hello 3</td>
</tr>
</tbody>
</table>

and it's showing up like this:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions