TASK-010: Fixed critical P0 bug preventing new project creation Problem: - Programmatic project.json generation had incorrect structure - Missing 'graph' object wrapper - Missing 'comments' and 'connections' arrays - Error: Cannot read properties of undefined (reading 'comments') Solution: - Corrected project.json structure with proper graph object - Added component id field - Included all required arrays (roots, connections, comments) - Added debug logging for better error tracking Impact: - New users can now create projects successfully - Unblocks user onboarding - No more cryptic error messages Documentation: - Added comprehensive entry to LEARNINGS.md - Created detailed CHANGELOG.md - Updated README.md with completion status
5.4 KiB
TASK-010: Project Creation Bug Fix - CHANGELOG
Status: ✅ COMPLETED
Date: January 9, 2026
Priority: P0 - Critical Blocker
Summary
Fixed critical bug preventing new project creation. The issue was an incorrect project.json structure in programmatic project generation - missing the required graph object wrapper and the comments array, causing TypeError: Cannot read properties of undefined (reading 'comments').
Changes Made
1. Fixed Project Structure in LocalProjectsModel.ts
File: packages/noodl-editor/src/editor/src/utils/LocalProjectsModel.ts
Problem: The programmatically generated project.json had an incorrect structure:
- Used
nodesarray directly in component (should begraph.roots) - Missing
graphobject wrapper - Missing
commentsarray (causing the error) - Missing
connectionsarray - Missing component
idfield
Solution: Corrected the structure to match the schema:
// BEFORE (INCORRECT)
{
name: 'App',
ports: [],
visual: true,
visualStateTransitions: [],
nodes: [...] // ❌ Wrong location
}
// AFTER (CORRECT)
{
name: 'App',
id: guid(), // ✅ Added
graph: { // ✅ Added wrapper
roots: [...], // ✅ Renamed from 'nodes'
connections: [], // ✅ Added
comments: [] // ✅ Added (was causing error)
},
metadata: {} // ✅ Added
}
Lines Modified: 288-321
2. Added Debug Logging
Added console logging for better debugging:
- Success message: "Project created successfully: {name}"
- Error messages for failure cases
Root Cause Analysis
The Error Chain
ProjectModel.fromJSON(json)
→ ComponentModel.fromJSON(json.components[i])
→ NodeGraphModel.fromJSON(json.graph) // ← json.graph was undefined!
→ accesses json.comments // ← BOOM: Cannot read properties of undefined
Why Previous Attempts Failed
- Attempt 1 (Path resolution with
__dirname): Webpack bundling issue - Attempt 2 (Path resolution with
process.cwd()): Wrong directory - Attempt 3 (Programmatic creation): Incomplete structure (this attempt)
The Final Solution
Understanding that the schema requires:
- Component needs
idfield - Component needs
graphobject (notnodesarray) graphmust containroots,connections, andcommentsarrays
Testing
Manual Testing Performed
- ✅ Created new project from dashboard
- ✅ Project opened without errors
- ✅ Console showed: "Project created successfully: alloha"
- ✅ Component "App" visible in editor
- ✅ Text node with "Hello World!" present
- ✅ Project can be saved and reopened
Success Criteria Met
- New users can create projects successfully
- No console errors during project creation
- Projects load correctly after creation
- All components are visible in the editor
- Error message resolved: "Cannot read properties of undefined (reading 'comments')"
Files Modified
- packages/noodl-editor/src/editor/src/utils/LocalProjectsModel.ts
- Lines 288-321: Fixed project.json structure
- Lines 324-345: Added better error logging
Documentation Updates
- dev-docs/reference/LEARNINGS.md
- Added comprehensive entry documenting the project.json structure
- Included prevention checklist for future programmatic project creation
- Documented the error chain and debugging journey
Impact
Before: P0 blocker - New users could not create projects at all
After: ✅ Project creation works correctly
User Experience:
- No more cryptic error messages
- Smooth onboarding for new users
- Reliable project creation
Related Issues
- Unblocks user onboarding
- Prerequisite for TASK-009 (template system refactoring)
- Fixes recurring issue that had three previous failed attempts
Notes for Future Developers
Project.json Schema Requirements
When creating projects programmatically, always include:
{
name: string,
components: [{
name: string,
id: string, // Required
graph: { // Required wrapper
roots: [...], // Not "nodes"
connections: [], // Required (can be empty)
comments: [] // Required (can be empty)
},
metadata: {} // Required (can be empty)
}],
settings: {}, // Required
metadata: { // Project metadata
title: string,
description: string
}
}
Prevention Checklist
Before creating a project programmatically:
- Component has
idfield - Component has
graphobject (notnodes) graph.rootsarray existsgraph.connectionsarray existsgraph.commentsarray exists- Component has
metadataobject - Project has
settingsobject - Project has
metadatawith title/description
Lessons Learned
- Schema documentation is critical: The lack of formal project.json schema documentation made this harder to debug
- Error messages can be misleading: "reading 'comments'" suggested comments were the problem, not the missing
graphobject - Test end-to-end: Don't just test file writing - test loading the created project
- Use real templates as reference: The truncated template file wasn't helpful; needed to examine actual working projects
Completed by: Cline (AI Assistant)
Reviewed by: Richard (User)
Date Completed: January 9, 2026