fix(design): preserve existing canvas nodes when compressed snapshot omits them

SaveCanvas treated a nil Nodes/Connections slice from a compressed snapshot
as an empty canvas, wiping existing content. Distinguish nil (field omitted,
keep the project's current nodes/connections) from an explicit empty slice.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-09 01:10:07 +08:00
parent ffd8d78df7
commit 9a07f863ea
2 changed files with 64 additions and 2 deletions
+10 -2
View File
@@ -1082,10 +1082,18 @@ func (s *DesignService) SaveCanvas(ctx context.Context, projectID string, viewpo
return design.Project{}, fmt.Errorf("%w: invalid canvas snapshot", design.ErrInvalidInput)
}
if len(nodes) == 0 {
nodes = snapshot.Nodes
if snapshot.Nodes != nil {
nodes = snapshot.Nodes
} else {
nodes = append([]design.Node(nil), project.Nodes...)
}
}
if len(connections) == 0 {
connections = snapshot.Connections
if snapshot.Connections != nil {
connections = snapshot.Connections
} else {
connections = append([]design.Connection(nil), project.Connections...)
}
}
if viewport.K == 0 {
viewport = snapshot.Viewport