You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
breaking: use structuredClone inside $state.snapshot (#12413)
* move cloning logic into new file, use structuredClone, add tests
* changeset
* breaking
* tweak
* use same cloning approach between server and client
* get types mostly working
* fix type error that popped up
* cheeky hack
* we no longer need deep_snapshot
* shallow copy state when freezing
* throw if argument is a state proxy
* docs
* regenerate
Copy file name to clipboardExpand all lines: documentation/docs/03-runes/01-state.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,7 @@ State declared with `$state.frozen` cannot be mutated; it can only be _reassigne
91
91
92
92
This can improve performance with large arrays and objects that you weren't planning to mutate anyway, since it avoids the cost of making them reactive. Note that frozen state can _contain_ reactive state (for example, a frozen array of reactive objects).
93
93
94
-
> Objects and arrays passed to `$state.frozen` will be shallowly frozen using `Object.freeze()`. If you don't want this, pass in a clone of the object or array instead.
94
+
> Objects and arrays passed to `$state.frozen` will be shallowly frozen using `Object.freeze()`. If you don't want this, pass in a clone of the object or array instead. The argument cannot be an existing state proxy created with `$state(...)`.
Copy file name to clipboardExpand all lines: packages/svelte/messages/client-errors/errors.md
+4
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,10 @@
64
64
65
65
> Snippets created with `createRawSnippet(...)` and used on the client must specify a `mount` function
66
66
67
+
## state_frozen_invalid_argument
68
+
69
+
> The argument to `$state.frozen(...)` cannot be an object created with `$state(...)`. You should create a copy of it first, for example with `$state.snapshot`
Copy file name to clipboardExpand all lines: packages/svelte/src/internal/client/errors.js
+16
Original file line number
Diff line number
Diff line change
@@ -278,6 +278,22 @@ export function snippet_missing_mount() {
278
278
}
279
279
}
280
280
281
+
/**
282
+
* The argument to `$state.frozen(...)` cannot be an object created with `$state(...)`. You should create a copy of it first, for example with `$state.snapshot`
283
+
* @returns {never}
284
+
*/
285
+
exportfunctionstate_frozen_invalid_argument(){
286
+
if(DEV){
287
+
consterror=newError(`state_frozen_invalid_argument\nThe argument to \`$state.frozen(...)\` cannot be an object created with \`$state(...)\`. You should create a copy of it first, for example with \`$state.snapshot\``);
0 commit comments