Merged in fix/SW-1831-accordion-error-key-prop-is-missing (pull request #1496)

fix(SW-1831): add fragment

* fix(SW-1831): add fragment

* fix(SW-1831): move fragment to nodesToHtml

* fix(SW-1831): remove import

* fix(SW-1831): add getUniqueId


Approved-by: Erik Tiekstra
Approved-by: Matilda Landström
This commit is contained in:
Fredrik Thorsson
2025-03-10 08:03:07 +00:00
parent b6ee3664f0
commit 44c9a15ea9
3 changed files with 16 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
import React from "react"
import { renderOptions } from "./renderOptions"
import styles from "./jsontohtml.module.css"
@@ -130,6 +132,13 @@ export function nodeToHtml(
}
}
function getUniqueId(node: RTENode) {
if ("uid" in node) {
return node.uid
}
return node.id
}
export function nodesToHtml(
nodes: RTENode[],
embedsArray: Node<Embeds>[],
@@ -137,7 +146,11 @@ export function nodesToHtml(
) {
const embeds = groupEmbedsByUid(embedsArray)
const fullRenderOptions = { ...renderOptions, ...overrideRenderOptions }
return nodes.map((node) => nodeToHtml(node, embeds, fullRenderOptions))
return nodes.map((node, index) => (
<React.Fragment key={getUniqueId(node) ?? `node-${index}`}>
{nodeToHtml(node, embeds, fullRenderOptions)}
</React.Fragment>
))
}
export function makeCssModuleCompatibleClassName(