From c10337cfb24e6cc4a2395bffc7d19c9de570335b Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 22 Feb 2024 16:09:40 +0000 Subject: [PATCH] fix: improve proxy effect dependency tracking (#10605) --- .changeset/cold-masks-learn.md | 5 +++++ packages/svelte/src/internal/client/proxy.js | 12 +++++++++--- .../samples/state-proxy-version/Item.svelte | 12 ++++++++++++ .../samples/state-proxy-version/_config.js | 9 +++++++++ .../samples/state-proxy-version/main.svelte | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 .changeset/cold-masks-learn.md create mode 100644 packages/svelte/tests/runtime-runes/samples/state-proxy-version/Item.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/state-proxy-version/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/state-proxy-version/main.svelte diff --git a/.changeset/cold-masks-learn.md b/.changeset/cold-masks-learn.md new file mode 100644 index 0000000000..1ecc5e3c65 --- /dev/null +++ b/.changeset/cold-masks-learn.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: improve proxy effect dependency tracking diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 36e24aa1b6..7106264e74 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -5,7 +5,8 @@ import { update, updating_derived, batch_inspect, - current_component_context + current_component_context, + set_ignore_mutation_validation } from './runtime.js'; import { effect_active } from './reactivity/computations.js'; import { @@ -182,7 +183,11 @@ const state_proxy_handler = { } if (s !== undefined) set(s, UNINITIALIZED); - if (boolean) update(metadata.v); + if (boolean) { + set_ignore_mutation_validation(true); + update(metadata.v); + set_ignore_mutation_validation(false); + } return boolean; }, @@ -291,8 +296,9 @@ const state_proxy_handler = { set(ls, length); } } - + set_ignore_mutation_validation(true); update(metadata.v); + set_ignore_mutation_validation(false); } return true; diff --git a/packages/svelte/tests/runtime-runes/samples/state-proxy-version/Item.svelte b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/Item.svelte new file mode 100644 index 0000000000..7c2a68d38b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/Item.svelte @@ -0,0 +1,12 @@ + + +
Item
diff --git a/packages/svelte/tests/runtime-runes/samples/state-proxy-version/_config.js b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/_config.js new file mode 100644 index 0000000000..ef12b6dd4f --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/_config.js @@ -0,0 +1,9 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + test({ assert, target }) { + flushSync(); + assert.htmlEqual(target.innerHTML, `
Item
`); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/state-proxy-version/main.svelte b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/main.svelte new file mode 100644 index 0000000000..980a4c2361 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/state-proxy-version/main.svelte @@ -0,0 +1,14 @@ + + +