Bugfix: Why did the Export Code button fail with 'Failed to generate...
Documentation for Sessions
🐛 Bugfix: Why did the Export Code button fail with 'Failed to generate...
Date: 2026-03-24
Time: 17:37:22 UTC
Session: gspace1-131.5
Agent: storage
Confidence: 98%
Status: ✅ Documented
📋 Decision Context
Question:
Why did the Export Code button fail with 'Failed to generate code' for all pages?
Task: Page builder production readiness — export fix
🎯 Decision Made
Chosen:
Updated page-validation.utils.ts to accept null as a valid parentId value alongside string and undefined
Options Considered:
- Fix the widget state to use undefined instead of null
- Update validation to accept null as valid parentId
- Remove parentId validation entirely
- Add a data migration to convert null to undefined on load
💭 Reasoning
Root cause: The validateWidget() function in page-validation.utils.ts checked if (w['parentId'] !== undefined && typeof w['parentId'] !== 'string') — this rejected null values since typeof null === 'object'. However, the page builder's widget state (persisted via autoFlashState/IndexedDB) stores parentId: null for top-level widgets (standard JavaScript pattern for 'no parent'). Every widget without a parent triggered a validation error, causing the code generator to reject the entire page before generating any code. The fix adds w['parentId'] !== null to the guard condition. This is a semantic validation gap: the validator was stricter than the actual data contract. Future validators should consider that IndexedDB/JSON serialization converts undefined to null.
📁 Files Involved
libs/libs-structural/page-builder/src/lib/utils/page-validation.utils.tslibs/libs-structural/page-builder/src/lib/page-builder.component.ts
🔗 Related
- Decision ID:
dev_1774373842172_v6wzmlw - Session: 131
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation