After some digging, I found that Objects wrapped in a Svelte 5 state rune don't behave just like a normal Object (unlike in Svelte 4), as $state(...)
wraps plain objects/arrays in a Svelte Proxy. This is what led to the error: IndexedDB (and Node’s structuredClone
) cannot serialize these Proxies, so Dexie throws DataCloneError: #<Object> could not be cloned
. The fix is to simply replace the plain object spread with $state.snapshot()
, which takes a static serializable snapshot of a deeply reactive $state
proxy:
- const dirty = { meta: { ...meta } }
+ const dirty = { meta: $state.snapshot(meta) }