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)}