Skip to content

Commit 31511f8

Browse files
committed
do a lot of stuff
1 parent 2a45896 commit 31511f8

File tree

6 files changed

+384
-24
lines changed

6 files changed

+384
-24
lines changed

.changeset/weak-flowers-sit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'svelte': patch
33
---
44

5-
patch structuredClone in dev to clone $state proxies
5+
patch structuredClone in dev to error on $state proxies

documentation/docs/98-reference/.generated/client-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,9 @@ Reading state that was created inside the same derived is forbidden. Consider us
129129
```
130130
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
131131
```
132+
133+
### structured_clone_state_proxy
134+
135+
```
136+
To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
137+
```

packages/svelte/messages/client-errors/errors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@
8383
## state_unsafe_mutation
8484

8585
> Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
86+
87+
## structured_clone_state_proxy
88+
89+
> To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`

packages/svelte/src/internal/client/errors.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,19 @@ export function state_unsafe_mutation() {
335335
} else {
336336
throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
337337
}
338+
}
339+
340+
/**
341+
* To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
342+
* @returns {never}
343+
*/
344+
export function structured_clone_state_proxy() {
345+
if (DEV) {
346+
const error = new Error(`structured_clone_state_proxy\nTo correctly clone a \`$state\` proxy, use \`$state.snapshot\` instead of \`structuredClone\`\nhttps://svelte.dev/e/structured_clone_state_proxy`);
347+
348+
error.name = 'Svelte error';
349+
throw error;
350+
} else {
351+
throw new Error(`https://svelte.dev/e/structured_clone_state_proxy`);
352+
}
338353
}

0 commit comments

Comments
 (0)