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:

  1. Fix the widget state to use undefined instead of null
  2. Update validation to accept null as valid parentId
  3. Remove parentId validation entirely
  4. 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


🔗 Related


Auto-generated by MCP Smart Consolidation