fix(core): coerce unknown material.preset to 'custom' (Sentry MONOREPO-EDITOR-DB)
Problem
Production editor crashes with an unhandled ZodError during slab boundary edits (Sentry MONOREPO-EDITOR-DB, issue id 7543527892):
ZodError: invalid_value at ["material","preset"]
expected one of white|brick|concrete|wood|glass|metal|plaster|tile|marble|custom
Stack: polygon-editor.tsx → slab/boundary-editor handlePolygonChange → use-scene updateNode → SlabNode.parse.
This happens when node data carries a material.preset value outside the MaterialPreset enum — typically legacy, imported, or AI-generated scenes (e.g. "stone").
Fix
In MaterialSchema, change:
preset: MaterialPreset.optional()
to:
preset: MaterialPreset.catch('custom').optional()
Unknown preset values are now coerced to 'custom' instead of throwing, making loading/updating tolerant of bad data. The exported MaterialPreset enum itself stays strict, so all other consumers keep exact enum validation. resolveMaterial already falls back to DEFAULT_MATERIALS.custom merged with material.properties for 'custom', so coerced materials render with whatever explicit properties the node carries.
Verified undefined handling: missing/undefined preset still parses to undefined (zod v4 .catch() before .optional() does not swallow undefined).
Tests
New packages/core/src/schema/material.test.ts:
- valid presets pass through unchanged (all 10 enum values)
- unknown preset (
'stone') coerces to'custom' - non-string preset coerces to
'custom' - missing / explicit-
undefinedpreset staysundefined
bun test src/schema/ → 50 pass, 0 fail; tsc --build clean; biome check clean.
Preview deployment for your docs. Learn more about Mintlify Previews.
| Project | Status | Preview | Updated (UTC) |
|---|---|---|---|
| pascal | 🔴 Failed | – | Jun 12, 2026, 4:14 AM |
💡 Tip: Enable Workflows to automatically generate PRs for you.