diff --git a/.changeset/loud-news-deliver.md b/.changeset/loud-news-deliver.md new file mode 100644 index 0000000000..f562caff8f --- /dev/null +++ b/.changeset/loud-news-deliver.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: allow deletion of $$restProps properties diff --git a/packages/svelte/src/internal/client/reactivity/props.js b/packages/svelte/src/internal/client/reactivity/props.js index b822f8d4ec..81c3e4d743 100644 --- a/packages/svelte/src/internal/client/reactivity/props.js +++ b/packages/svelte/src/internal/client/reactivity/props.js @@ -126,6 +126,13 @@ const legacy_rest_props_handler = { }; } }, + deleteProperty(target, key) { + // Svelte 4 allowed for deletions on $$restProps + if (target.exclude.includes(key)) return false; + target.exclude.push(key); + update(target.version); + return true; + }, has(target, key) { if (target.exclude.includes(key)) return false; return key in target.props; diff --git a/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/App.svelte b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/App.svelte new file mode 100644 index 0000000000..37825576e5 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/App.svelte @@ -0,0 +1,10 @@ + + + + +{JSON.stringify($$restProps)} diff --git a/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/_config.js b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/_config.js new file mode 100644 index 0000000000..853af731f9 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/_config.js @@ -0,0 +1,15 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + html: `\n{"a":1,"b":2}`, + + test({ assert, target }) { + const [btn1] = target.querySelectorAll('button'); + + btn1.click(); + flushSync(); + + assert.htmlEqual(target.innerHTML, `\n{"b":2}`); + } +}); diff --git a/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/main.svelte b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/main.svelte new file mode 100644 index 0000000000..461848a3b3 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/rest-props-delete/main.svelte @@ -0,0 +1,5 @@ + + +