Skip to content

Commit b73052f

Browse files
fix: make ownership widening more robust to userland proxies (#13377)
Fixes #13376
1 parent 3ee8e0b commit b73052f

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.changeset/nice-brooms-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: make ownership widening more robust to userland proxies

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,13 @@ function add_owner_to_object(object, owner, seen) {
170170

171171
if (metadata) {
172172
// this is a state proxy, add owner directly, if not globally shared
173-
if (metadata.owners !== null) {
173+
if ('owners' in metadata && metadata.owners != null) {
174174
metadata.owners.add(owner);
175175
}
176176
} else if (object && typeof object === 'object') {
177177
if (seen.has(object)) return;
178178
seen.add(object);
179-
180-
if (object[ADD_OWNER]) {
179+
if (ADD_OWNER in object && object[ADD_OWNER]) {
181180
// this is a class with state fields. we put this in a render effect
182181
// so that if state is replaced (e.g. `instance.name = { first, last }`)
183182
// the new state is also co-owned by the caller of `getContext`
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true
6+
}
7+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { setContext, getContext } from "svelte";
3+
4+
setContext("", new Proxy({}, {
5+
get(){
6+
return {}
7+
}
8+
}));
9+
10+
getContext("");
11+
</script>

0 commit comments

Comments
 (0)