From 1e3e602e1d0b61f128a87ef6f2b33edb4557f749 Mon Sep 17 00:00:00 2001 From: Anton Pascal Date: Tue, 12 May 2026 04:06:07 +0000 Subject: [PATCH] fix(editor): guard door segment columnRatios against undefined Add defensive null guards for seg.columnRatios and seg.dividerThickness in addLeafSegmentContent(). Legacy door nodes stored in the database may lack these fields since they were added later to the Zod schema with defaults. Without the guard, accessing .length on undefined crashes the viewer (Sentry EDITOR-AM, 487 events in 1 hour burst). --- .../viewer/src/systems/door/door-system.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/viewer/src/systems/door/door-system.tsx b/packages/viewer/src/systems/door/door-system.tsx index f309a55a..796eafbc 100644 --- a/packages/viewer/src/systems/door/door-system.tsx +++ b/packages/viewer/src/systems/door/door-system.tsx @@ -477,17 +477,19 @@ function addLeafSegmentContent({ for (const seg of segments) { const segH = (seg.heightRatio / totalRatio) * contentH const segCenterY = segY - segH / 2 - const numCols = seg.columnRatios.length - const colSum = seg.columnRatios.reduce((a, b) => a + b, 0) - const usableW = contentW - (numCols - 1) * seg.dividerThickness - const colWidths = seg.columnRatios.map((r) => (r / colSum) * usableW) + const columnRatios = seg.columnRatios ?? [1] + const dividerThickness = seg.dividerThickness ?? 0.03 + const numCols = columnRatios.length + const colSum = columnRatios.reduce((a, b) => a + b, 0) + const usableW = contentW - (numCols - 1) * dividerThickness + const colWidths = columnRatios.map((r) => (r / colSum) * usableW) const colXCenters: number[] = [] let cx = leafCenterX - contentW / 2 for (let c = 0; c < numCols; c++) { colXCenters.push(cx + colWidths[c]! / 2) cx += colWidths[c]! - if (c < numCols - 1) cx += seg.dividerThickness + if (c < numCols - 1) cx += dividerThickness } if (seg.type !== 'empty') { @@ -496,14 +498,14 @@ function addLeafSegmentContent({ cx += colWidths[c]! addLeafBox( baseMaterial, - seg.dividerThickness, + dividerThickness, segH, leafDepth + 0.001, - cx + seg.dividerThickness / 2, + cx + dividerThickness / 2, segCenterY, 0, ) - cx += seg.dividerThickness + cx += dividerThickness } }