mirror of https://github.com/sveltejs/svelte
fix: widen ownership when sub state is assigned to new state (#11217)
Ownership was not widened when assigning a sub state to a different top level state. The set of owners for the state was zero because the owner was on the original parent, but that one was reset to null because it's now the top level of a different state. That meant that there was no owner but also no parent to check for the owner, which is an invalid combination resulting in a nullpointer (and also potentially false positive warnings in other situations). fixes #11204pull/11219/head
parent
c44234dc2f
commit
4b59ef3c41
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: widen ownership when sub state is assigned to new state
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
let { item } = $props();
|
||||||
|
|
||||||
|
function onclick() {
|
||||||
|
item.name = `${item.name} edited`
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>{item?.name}</div>
|
||||||
|
<button {onclick}>Then click here</button>
|
@ -0,0 +1,41 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
/** @type {typeof console.warn} */
|
||||||
|
let warn;
|
||||||
|
|
||||||
|
/** @type {any[]} */
|
||||||
|
let warnings = [];
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
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 [btn1, btn2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
btn1.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.deepEqual(warnings.length, 0);
|
||||||
|
|
||||||
|
btn2.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.deepEqual(warnings.length, 1);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let items = $state([{ id: "test", name: "this is a test"}, { id:"test2", name: "this is a second test"}]);
|
||||||
|
let found = $state();
|
||||||
|
|
||||||
|
function onclick() {
|
||||||
|
found = items.find(c => c.id === 'test2');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button {onclick}>First click here</button>
|
||||||
|
<Child item={found} />
|
Loading…
Reference in new issue