From fde6f81df3f0fd3dc73fd7f43a797447a65e08ea Mon Sep 17 00:00:00 2001 From: anton-pascal Date: Fri, 10 Jul 2026 04:05:35 +0000 Subject: [PATCH] fix(core): guard material-ref parsers against non-string values (Sentry MONOREPO-EDITOR-EM) getLibraryMaterialIdFromRef and getSceneMaterialIdFromRef only guarded against null/undefined, then called .startsWith(). When a non-string material ref reaches them (legacy/malformed wall material slot ref), .startsWith is undefined -> TypeError: e.startsWith is not a function. Narrow with typeof !== 'string' -> return null, so a bad ref degrades to 'no library/scene material' instead of throwing during wall material resolution (packages/viewer wall-materials.ts -> parseMaterialRef). --- packages/core/src/material-library.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/material-library.ts b/packages/core/src/material-library.ts index ca1ab1b93..074b07e5f 100644 --- a/packages/core/src/material-library.ts +++ b/packages/core/src/material-library.ts @@ -4187,13 +4187,14 @@ export function toSceneMaterialRef(id: string) { } export function getLibraryMaterialIdFromRef(materialRef?: string | null) { - if (!materialRef) return null + if (typeof materialRef !== 'string') return null if (!materialRef.startsWith(LIBRARY_MATERIAL_REF_PREFIX)) return null return materialRef.slice(LIBRARY_MATERIAL_REF_PREFIX.length) } export function getSceneMaterialIdFromRef(materialRef?: string | null): string | null { - if (!materialRef?.startsWith(SCENE_MATERIAL_REF_PREFIX)) return null + if (typeof materialRef !== 'string') return null + if (!materialRef.startsWith(SCENE_MATERIAL_REF_PREFIX)) return null return materialRef.slice(SCENE_MATERIAL_REF_PREFIX.length) }