fix: serialize effects properly to avoid DataCloneError

Effects contain non-serializable data like functions and audio nodes that
cannot be stored in IndexedDB. Added proper serialization.

Changes:
- Added serializeEffects function to strip non-serializable data
- Uses JSON parse/stringify to deep clone parameters
- Preserves effect type, name, enabled state, and parameters
- Fixes DataCloneError when saving projects with effects

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-19 09:56:02 +01:00
parent 0d86cff1b7
commit 67abbb20cb

View File

@@ -27,6 +27,20 @@ export function generateProjectId(): string {
return `project_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
/**
* Serialize effects by removing any non-serializable data (functions, nodes, etc.)
*/
function serializeEffects(effects: any[]): any[] {
return effects.map(effect => ({
id: effect.id,
type: effect.type,
name: effect.name,
enabled: effect.enabled,
expanded: effect.expanded,
parameters: effect.parameters ? JSON.parse(JSON.stringify(effect.parameters)) : undefined,
}));
}
/**
* Convert tracks to serialized format
*/
@@ -42,7 +56,7 @@ function serializeTracks(tracks: Track[]): SerializedTrack[] {
collapsed: track.collapsed,
height: track.height,
audioBuffer: track.audioBuffer ? serializeAudioBuffer(track.audioBuffer) : null,
effects: track.effectChain?.effects || [],
effects: serializeEffects(track.effectChain?.effects || []),
automation: track.automation,
recordEnabled: track.recordEnabled,
}));