diff --git a/documentation/docs/98-reference/.generated/client-errors.md b/documentation/docs/98-reference/.generated/client-errors.md index eaedbb2f665b..2c2e0707ea12 100644 --- a/documentation/docs/98-reference/.generated/client-errors.md +++ b/documentation/docs/98-reference/.generated/client-errors.md @@ -133,9 +133,3 @@ 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` -``` diff --git a/documentation/docs/98-reference/.generated/shared-errors.md b/documentation/docs/98-reference/.generated/shared-errors.md index 0102aafcbca1..505d05f85e4f 100644 --- a/documentation/docs/98-reference/.generated/shared-errors.md +++ b/documentation/docs/98-reference/.generated/shared-errors.md @@ -60,6 +60,12 @@ Certain lifecycle methods can only be used during component initialisation. To f `%name%` is not a store with a `subscribe` method ``` +### structured_clone_state_proxy + +``` +To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone` +``` + ### svelte_element_invalid_this_value ``` diff --git a/packages/svelte/messages/client-errors/errors.md b/packages/svelte/messages/client-errors/errors.md index 2e36759f03a0..ce1f222c63ea 100644 --- a/packages/svelte/messages/client-errors/errors.md +++ b/packages/svelte/messages/client-errors/errors.md @@ -87,7 +87,3 @@ See the [migration guide](/docs/svelte/v5-migration-guide#Components-are-no-long ## 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` diff --git a/packages/svelte/messages/shared-errors/errors.md b/packages/svelte/messages/shared-errors/errors.md index 8b4c61303a07..b1aeeb0edff6 100644 --- a/packages/svelte/messages/shared-errors/errors.md +++ b/packages/svelte/messages/shared-errors/errors.md @@ -52,6 +52,10 @@ Certain lifecycle methods can only be used during component initialisation. To f > `%name%` is not a store with a `subscribe` method +## structured_clone_state_proxy + +> To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone` + ## svelte_element_invalid_this_value > The `this` prop on `` must be a string, if defined diff --git a/packages/svelte/src/internal/client/errors.js b/packages/svelte/src/internal/client/errors.js index ed7e59b5969a..682816e1d64b 100644 --- a/packages/svelte/src/internal/client/errors.js +++ b/packages/svelte/src/internal/client/errors.js @@ -335,19 +335,4 @@ 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`); - } } \ No newline at end of file diff --git a/packages/svelte/src/internal/shared/clone.js b/packages/svelte/src/internal/shared/clone.js index 5bb267e01af6..8346db61826d 100644 --- a/packages/svelte/src/internal/shared/clone.js +++ b/packages/svelte/src/internal/shared/clone.js @@ -2,7 +2,7 @@ import { DEV } from 'esm-env'; import { STATE_SYMBOL } from '../client/constants.js'; import * as w from './warnings.js'; -import * as e from '../client/errors.js'; +import * as e from './errors.js'; import { get_prototype_of, is_array, diff --git a/packages/svelte/src/internal/shared/errors.js b/packages/svelte/src/internal/shared/errors.js index 26d6822cdb29..32ca850cf81e 100644 --- a/packages/svelte/src/internal/shared/errors.js +++ b/packages/svelte/src/internal/shared/errors.js @@ -62,4 +62,19 @@ export function svelte_element_invalid_this_value() { } else { throw new Error(`https://svelte.dev/e/svelte_element_invalid_this_value`); } +} + +/** + * 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`); + } } \ No newline at end of file