Skip to content

Commit

Permalink
chore: rewrite state_unsafe_mutation message (#12059)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Jun 17, 2024
1 parent 0ef906c commit 6588d85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-glasses-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: rewrite state_unsafe_mutation message
4 changes: 1 addition & 3 deletions packages/svelte/messages/client-errors/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
## state_unsafe_mutation

> Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. This can lead to unexpected errors and possibly cause infinite loops.
>
> If the object is not meant to be reactive, declare it without `$state`
> Updating state inside a derived is forbidden. If the value should not be reactive, declare it without `$state`
## svelte_component_invalid_this_value

Expand Down
6 changes: 2 additions & 4 deletions packages/svelte/src/internal/client/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,12 @@ export function state_prototype_fixed() {
}

/**
* Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. This can lead to unexpected errors and possibly cause infinite loops.
*
* If the object is not meant to be reactive, declare it without `$state`
* Updating state inside a derived is forbidden. If the value should not be reactive, declare it without `$state`
* @returns {never}
*/
export function state_unsafe_mutation() {
if (DEV) {
const error = new Error(`${"state_unsafe_mutation"}\n${"Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. This can lead to unexpected errors and possibly cause infinite loops.\n\nIf the object is not meant to be reactive, declare it without `$state`"}`);
const error = new Error(`${"state_unsafe_mutation"}\n${"Updating state inside a derived is forbidden. If the value should not be reactive, declare it without `$state`"}`);

error.name = 'Svelte error';
throw error;
Expand Down

0 comments on commit 6588d85

Please sign in to comment.