From 6588d85364585b12726ed4c446806b3156e090f7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 17 Jun 2024 07:44:39 -0700 Subject: [PATCH] chore: rewrite state_unsafe_mutation message (#12059) --- .changeset/nasty-glasses-begin.md | 5 +++++ packages/svelte/messages/client-errors/errors.md | 4 +--- packages/svelte/src/internal/client/errors.js | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .changeset/nasty-glasses-begin.md diff --git a/.changeset/nasty-glasses-begin.md b/.changeset/nasty-glasses-begin.md new file mode 100644 index 0000000000..7a7621b2ec --- /dev/null +++ b/.changeset/nasty-glasses-begin.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: rewrite state_unsafe_mutation message diff --git a/packages/svelte/messages/client-errors/errors.md b/packages/svelte/messages/client-errors/errors.md index ec543765cf..3e64b90899 100644 --- a/packages/svelte/messages/client-errors/errors.md +++ b/packages/svelte/messages/client-errors/errors.md @@ -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 diff --git a/packages/svelte/src/internal/client/errors.js b/packages/svelte/src/internal/client/errors.js index 232cc2eeee..e344c552da 100644 --- a/packages/svelte/src/internal/client/errors.js +++ b/packages/svelte/src/internal/client/errors.js @@ -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;