fix: make ownership widening more robust to userland proxies (#13377)

Fixes #13376
pull/13406/head
Paolo Ricciuti 1 month ago committed by GitHub
parent 3ee8e0b14c
commit b73052f590
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: make ownership widening more robust to userland proxies

@ -170,14 +170,13 @@ function add_owner_to_object(object, owner, seen) {
if (metadata) {
// this is a state proxy, add owner directly, if not globally shared
if (metadata.owners !== null) {
if ('owners' in metadata && metadata.owners != null) {
metadata.owners.add(owner);
}
} else if (object && typeof object === 'object') {
if (seen.has(object)) return;
seen.add(object);
if (object[ADD_OWNER]) {
if (ADD_OWNER in object && object[ADD_OWNER]) {
// this is a class with state fields. we put this in a render effect
// so that if state is replaced (e.g. `instance.name = { first, last }`)
// the new state is also co-owned by the caller of `getContext`

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
}
});

@ -0,0 +1,11 @@
<script>
import { setContext, getContext } from "svelte";
setContext("", new Proxy({}, {
get(){
return {}
}
}));
getContext("");
</script>
Loading…
Cancel
Save