Skip to content

Commit 98eeb1d

Browse files
authored
fix(nodes): coalesce node.children to [] in container renderers (pascalorg#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.
1 parent 1256331 commit 98eeb1d

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/nodes/src/building/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const BuildingRenderer = ({ node }: { node: BuildingNode }) => {
1818
rotation={[node.rotation[0], node.rotation[1], node.rotation[2]]}
1919
{...handlers}
2020
>
21-
{node.children.map((childId) => (
21+
{(node.children ?? []).map((childId) => (
2222
<NodeRenderer key={childId} nodeId={childId} />
2323
))}
2424
</group>

packages/nodes/src/ceiling/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const CeilingRenderer = ({ node }: { node: CeilingNode }) => {
127127
scale={0}
128128
visible={false}
129129
/>
130-
{node.children.map((childId) => (
130+
{(node.children ?? []).map((childId) => (
131131
<NodeRenderer key={childId} nodeId={childId} />
132132
))}
133133
</mesh>

packages/nodes/src/site/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const SiteRenderer = ({ node }: { node: SiteNode }) => {
139139
return (
140140
<group ref={ref} {...handlers}>
141141
{/* Render children (buildings and items) */}
142-
{node.children.map((childId) => (
142+
{(node.children ?? []).map((childId) => (
143143
<NodeRenderer key={childId} nodeId={childId as AnyNodeId} />
144144
))}
145145

packages/nodes/src/wall/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const WallRenderer = ({ node }: { node: WallNode }) => {
7878
{...handlers}
7979
/>
8080

81-
{node.children.map((childId) => (
81+
{(node.children ?? []).map((childId) => (
8282
<NodeRenderer key={`${node.id}:${childId}`} nodeId={childId} />
8383
))}
8484
</mesh>

0 commit comments

Comments
 (0)