From 9161448ee5edf92e4bdf1efedd54c07787d46a40 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 12 Feb 2024 13:52:21 +0000 Subject: [PATCH] fix: improve handling of object property deletions (#10456) * fix: improve handling of object property deletions * revert * revert * revert --- .changeset/orange-crews-rescue.md | 5 +++++ packages/svelte/src/internal/client/proxy.js | 2 +- .../samples/state-delete-property/_config.js | 20 +++++++++++++++++++ .../samples/state-delete-property/main.svelte | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .changeset/orange-crews-rescue.md create mode 100644 packages/svelte/tests/runtime-runes/samples/state-delete-property/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/state-delete-property/main.svelte diff --git a/.changeset/orange-crews-rescue.md b/.changeset/orange-crews-rescue.md new file mode 100644 index 0000000000..e45228711e --- /dev/null +++ b/.changeset/orange-crews-rescue.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: improve handling of object property deletions diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 0fff0447c0..b988bb4c55 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -157,7 +157,7 @@ const state_proxy_handler = { } if (s !== undefined) set(s, UNINITIALIZED); - if (prop in target) update(metadata.v); + if (boolean) update(metadata.v); return boolean; }, diff --git a/packages/svelte/tests/runtime-runes/samples/state-delete-property/_config.js b/packages/svelte/tests/runtime-runes/samples/state-delete-property/_config.js new file mode 100644 index 0000000000..dab129d80e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/state-delete-property/_config.js @@ -0,0 +1,20 @@ +import { test } from '../../test'; + +export default test({ + html: '

a,b,c

{"a":1,"b":2,"c":3}

', + async test({ assert, target }) { + const [btn, bt2] = target.querySelectorAll('button'); + + await btn?.click(); + assert.htmlEqual( + target.innerHTML, + `

a,b,c

{"a":1,"b":2,"c":3}

` + ); + + await bt2?.click(); + assert.htmlEqual( + target.innerHTML, + `

a,c

{"a":1,"c":3}

` + ); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/state-delete-property/main.svelte b/packages/svelte/tests/runtime-runes/samples/state-delete-property/main.svelte new file mode 100644 index 0000000000..974742a231 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/state-delete-property/main.svelte @@ -0,0 +1,8 @@ + + + + +

{Object.keys(numbers)}

+

{JSON.stringify(numbers)}