fix: ensure proxy owner set always has 1 or more members (#10577)

* fix missing owners

* regression test

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10579/head
Rich Harris 2 years ago committed by GitHub
parent 88389ad2cf
commit ddb968cc35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: inherit ownerlessness when creating child proxies

@ -84,7 +84,7 @@ export function proxy(value, immutable = true, owners) {
? // @ts-expect-error
new Set([current_component_context.function])
: null
: new Set(owners);
: owners && new Set(owners);
}
return proxy;

@ -0,0 +1,37 @@
import { test } from '../../test';
/** @type {typeof console.warn} */
let warn;
/** @type {any[]} */
let warnings = [];
export default test({
html: `<button>clicks: 0</button>`,
compileOptions: {
dev: true
},
before_test: () => {
warn = console.warn;
console.warn = (...args) => {
warnings.push(...args);
};
},
after_test: () => {
console.warn = warn;
warnings = [];
},
async test({ assert, target }) {
const btn = target.querySelector('button');
await btn?.click();
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button>`);
assert.deepEqual(warnings, []);
}
});

@ -0,0 +1,9 @@
<script>
import { global } from './state.svelte.js';
global.a = { b: 0 };
</script>
<button onclick={() => global.a.b += 1}>
clicks: {global.a.b}
</button>
Loading…
Cancel
Save