fix(nodes): coalesce node.children to [] in container renderers (#333)
Guards building/ceiling/site/wall renderers with `(node.children ?? [])` so a node whose `children` array is missing (legacy/unparsed scene data) no longer crashes the renderer with "Cannot read properties of undefined (reading 'map')" (EDITOR-C0). Matches the existing guard in roof/renderer.tsx and the Array.isArray check in the parametric renderer. Note: the schema declares `children: z.array(...).default([])`, so this can only be hit by data that bypasses Zod normalization on load. This is a defense-in-depth crash-stopper; the deeper fix is to normalize/parse legacy nodes in migrateNodes (use-scene.ts) so missing arrays are repaired before render — tracked as a follow-up.
This commit is contained in:
@@ -18,7 +18,7 @@ export const BuildingRenderer = ({ node }: { node: BuildingNode }) => {
|
||||
rotation={[node.rotation[0], node.rotation[1], node.rotation[2]]}
|
||||
{...handlers}
|
||||
>
|
||||
{node.children.map((childId) => (
|
||||
{(node.children ?? []).map((childId) => (
|
||||
<NodeRenderer key={childId} nodeId={childId} />
|
||||
))}
|
||||
</group>
|
||||
|
||||
@@ -127,7 +127,7 @@ export const CeilingRenderer = ({ node }: { node: CeilingNode }) => {
|
||||
scale={0}
|
||||
visible={false}
|
||||
/>
|
||||
{node.children.map((childId) => (
|
||||
{(node.children ?? []).map((childId) => (
|
||||
<NodeRenderer key={childId} nodeId={childId} />
|
||||
))}
|
||||
</mesh>
|
||||
|
||||
@@ -139,7 +139,7 @@ export const SiteRenderer = ({ node }: { node: SiteNode }) => {
|
||||
return (
|
||||
<group ref={ref} {...handlers}>
|
||||
{/* Render children (buildings and items) */}
|
||||
{node.children.map((childId) => (
|
||||
{(node.children ?? []).map((childId) => (
|
||||
<NodeRenderer key={childId} nodeId={childId as AnyNodeId} />
|
||||
))}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ const WallRenderer = ({ node }: { node: WallNode }) => {
|
||||
{...handlers}
|
||||
/>
|
||||
|
||||
{node.children.map((childId) => (
|
||||
{(node.children ?? []).map((childId) => (
|
||||
<NodeRenderer key={`${node.id}:${childId}`} nodeId={childId} />
|
||||
))}
|
||||
</mesh>
|
||||
|
||||
Reference in New Issue
Block a user