Commit 59c487b
Fix critical node position format transformation bug
Fixed "Cannot read properties of undefined (reading 'x')" error when
rendering diagrams in canvas view.
## Problem
.bac4 files store node positions as:
```json
{
"id": "node-1",
"type": "system",
"x": 100,
"y": 200,
"data": {...}
}
```
React Flow expects:
```json
{
"id": "node-1",
"type": "system",
"position": { "x": 100, "y": 200 },
"data": {...}
}
```
Previous code loaded .bac4 files directly without transformation,
causing React Flow to fail when accessing `node.position.x`.
## Solution
Implemented bidirectional transformation in useFileOperations.ts:
**Loading (file → React Flow):**
```typescript
const transformedNodes = validatedNodes.map((node: any) => {
const { x, y, ...rest } = node;
return {
...rest,
position: { x: x || 0, y: y || 0 },
};
});
```
**Saving (React Flow → file):**
```typescript
const savedNodes = inMemorySnapshot.nodes.map((memNode: any) => {
const { position, ...restNode } = memNode;
return {
...restNode,
x: position?.x || 0,
y: position?.y || 0,
};
});
```
## Impact
- ✅ Diagrams now render correctly in canvas view
- ✅ Node positions preserved when saving
- ✅ Backward compatible with existing .bac4 files
- ✅ Cross-references still preserved correctly
## Testing
Tested with:
- 16 BA Engineering diagrams in BAC4Testv09 vault
- All diagrams load and render correctly
- Manual node repositioning works
- File save/reload preserves positions
- Cross-reference nodes maintain references
## Files Changed
- src/ui/canvas/hooks/useFileOperations.ts
- Added transformedNodes mapping on load (line 309-313)
- Added fileFormatNode mapping on save (line 132-137)
- Preserved cross-reference logic with new format
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 3060f0c commit 59c487b
1 file changed
Lines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
129 | 139 | | |
130 | 140 | | |
131 | 141 | | |
132 | | - | |
| 142 | + | |
133 | 143 | | |
134 | | - | |
| 144 | + | |
135 | 145 | | |
136 | 146 | | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
141 | | - | |
| 151 | + | |
142 | 152 | | |
143 | 153 | | |
144 | 154 | | |
| |||
293 | 303 | | |
294 | 304 | | |
295 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
296 | 317 | | |
297 | 318 | | |
298 | 319 | | |
299 | | - | |
| 320 | + | |
300 | 321 | | |
301 | 322 | | |
302 | | - | |
| 323 | + | |
303 | 324 | | |
304 | 325 | | |
305 | 326 | | |
| |||
0 commit comments