Prompt file imported from wtyler2505/circuitmind-ai (
.codex/prompts/react-foreach-undefined-debug.md). Copyright stays with the author.
description: Debug React/TS runtime error "Cannot read properties of undefined (reading 'forEach')" and propose fixes with tests. argument-hint: [FILE="components/DesignAssistant.tsx"] [SYMBOL="modeMap"] [STACK_TRACE="..."] allowed-tools: Read, Write, Edit, Bash
React forEach Undefined Debug
Goal: identify root cause and fix without regression.
Steps
- Locate the failing forEach call and identify the variable source.
- Check initialization, props, async loads, optional chaining, default values.
- Propose a fix (guard, default empty array, type refinement).
- Add or adjust tests for undefined and empty cases.
- Summarize changes and why they are safe.
Output
- Root cause:
- Fix:
- Tests:
- Files touched:
