-
I'm trying to migrate my project to Svelte 5, and encountered an error by const obj = writable({ user: { name: 'one' } });
console.log(1, $obj); // Object
const obj2 = structuredClone($obj); // fine
$obj = { user: { name: 'two'} };
console.log(2, $obj); // Proxy
const obj3 = structuredClone($obj); // DataCloneError
https://svelte.dev/playground/66ed5c5340a44a2da72514f21dc150b8?version=5.20.0 The Svelte 5 migration guide mentions Proxy, and the HTML Standard spec explains a Proxy instance results this error. This doesn't seems to be a bug. But how should I proceed with my migration? Does anyone have any suggestions on how to deal with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
please use <script lang="ts">
import { writable } from 'svelte/store';
const props = $props(); // !?
const obj = writable({ name: 'Yo' });
console.log(1, $obj); // Object
const obj2 = structuredClone($obj); // fine
$obj = { name: 'Hey' };
const snapshot = $state.snapshot($obj);
console.log(2, snapshot);
const obj3 = structuredClone(snapshot);
</script> |
Beta Was this translation helpful? Give feedback.
please use
$state.snapshot
.