-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: widen ownership upon property access if necessary (#13175)
In case of something like `foo = bar.map(...)`, foo would have ownership of the array itself, while the individual items would have ownership of the component that created the proxy. That means if we later do `foo[0].baz = 42`, we could get a false-positive ownership violation, since the two proxies are not connected to each other via the parent relationship. For this reason, we need to widen the ownership of the children upon access when we detect they are not connected. Fixes #13137
- Loading branch information
1 parent
fd7e8b7
commit 3808935
Showing
6 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: widen ownership upon property access if necessary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...es/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-7/Component1.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
import Component2 from './Component2.svelte'; | ||
let { rows = $bindable([]) } = $props(); | ||
let rows2 = $state([]); | ||
$effect(() => { | ||
rows2 = rows.slice(); | ||
}); | ||
</script> | ||
|
||
<Component2 bind:rows={rows2} /> |
7 changes: 7 additions & 0 deletions
7
...es/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-7/Component2.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let { rows = $bindable([]) } = $props(); | ||
</script> | ||
|
||
{#if rows.length} | ||
<input type="checkbox" bind:checked={rows[0].check} /> | ||
{/if} |
22 changes: 22 additions & 0 deletions
22
packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-7/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { flushSync } from 'svelte'; | ||
import { ok, test } from '../../test'; | ||
|
||
// Tests that proxies widen ownership correctly even if not directly connected to each other | ||
export default test({ | ||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
test({ assert, target, warnings }) { | ||
const input = target.querySelector('input'); | ||
ok(input); | ||
|
||
input.checked = true; | ||
input.dispatchEvent(new Event('input', { bubbles: true })); | ||
flushSync(); | ||
|
||
assert.deepEqual(warnings, []); | ||
}, | ||
|
||
warnings: [] | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/svelte/tests/runtime-runes/samples/non-local-mutation-with-binding-7/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
import Component1 from './Component1.svelte'; | ||
let rows = $state([{}]); | ||
</script> | ||
|
||
<Component1 bind:rows /> |