fix(studio): Duplicate keys in NamespaceTree

This commit is contained in:
Cole Lawrence 2022-05-20 12:02:38 -04:00
parent 9cf5c38aee
commit e28a084dbb

View file

@ -40,10 +40,11 @@ function NamespaceTree(props: {
<> <>
{[...props.namespace.entries()].map(([label, {object, nested}]) => { {[...props.namespace.entries()].map(([label, {object, nested}]) => {
const children = ( const children = (
<> <React.Fragment key={`${label} - ${props.visualIndentation}`}>
{object && ( {object && (
<ObjectItem <ObjectItem
depth={props.visualIndentation} depth={props.visualIndentation}
// key is useful for navigating react dev component tree
key={'objectPath(' + object.address.objectKey + ')'} key={'objectPath(' + object.address.objectKey + ')'}
// object entries should not allow this to be undefined // object entries should not allow this to be undefined
sheetObject={object} sheetObject={object}
@ -53,16 +54,20 @@ function NamespaceTree(props: {
{nested && ( {nested && (
<NamespaceTree <NamespaceTree
namespace={nested} namespace={nested}
// Question: will there be key conflict if two components have the same labels?
key={'namespaceTree(' + label + ')'}
visualIndentation={props.visualIndentation + 1} visualIndentation={props.visualIndentation + 1}
/> />
)} )}
</> </React.Fragment>
) )
return nested ? ( return nested ? (
<BaseItem <BaseItem
selectionStatus="not-selectable" selectionStatus="not-selectable"
label={label} label={label}
// key necessary for no duplicate keys (next to other React.Fragments)
key={`baseItem(${label})`}
depth={props.visualIndentation} depth={props.visualIndentation}
children={children} children={children}
/> />