Skip to content

Commit

Permalink
do a lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocean-OS committed Dec 22, 2024
1 parent 2a45896 commit 31511f8
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .changeset/weak-flowers-sit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'svelte': patch
---

patch structuredClone in dev to clone $state proxies
patch structuredClone in dev to error on $state proxies
6 changes: 6 additions & 0 deletions documentation/docs/98-reference/.generated/client-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ Reading state that was created inside the same derived is forbidden. Consider us
```
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
```

### structured_clone_state_proxy

```
To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
```
4 changes: 4 additions & 0 deletions packages/svelte/messages/client-errors/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@
## state_unsafe_mutation

> Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
## structured_clone_state_proxy

> To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
15 changes: 15 additions & 0 deletions packages/svelte/src/internal/client/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,19 @@ export function state_unsafe_mutation() {
} else {
throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
}
}

/**
* To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
* @returns {never}
*/
export function structured_clone_state_proxy() {
if (DEV) {
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`);

error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/structured_clone_state_proxy`);
}
}
Loading

0 comments on commit 31511f8

Please sign in to comment.