mirror of https://github.com/sveltejs/svelte
fix: improve handling of unowned derived signals (#10342)
parent
145b233041
commit
23b38a3471
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve handling of unowned derived signals
|
@ -0,0 +1,12 @@
|
||||
<script context="module">
|
||||
class Store {
|
||||
all = $state([1,2,3]);
|
||||
d1 = $derived(this.all.filter(a => a > 2));
|
||||
|
||||
update_value(){
|
||||
this.all = [1,2,3,4,5];
|
||||
}
|
||||
}
|
||||
export const s = new Store();
|
||||
|
||||
</script>
|
@ -0,0 +1,15 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: '<div>d2: 3</div><div>d3: 3</div><div>d4: 3</div>',
|
||||
skip_if_hydrate: 'permanent',
|
||||
|
||||
async test({ assert, target }) {
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<div>d2: 3,4,5</div><div>d3: 3,4,5</div><div>d4: 3,4,5</div>'
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import {s} from "./Component.svelte";
|
||||
import {onMount}from "svelte";
|
||||
|
||||
let d2 = $derived(s.d1.filter(x => x > 2));
|
||||
let d3 = $derived(s.all.filter(x => x > 2));
|
||||
|
||||
onMount(()=>{
|
||||
queueMicrotask(() => {
|
||||
s.update_value();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div>d2: {d2.join(',')}</div>
|
||||
<div>d3: {d3.join(',')}</div>
|
||||
<div>d4: {d3.join(',')}</div>
|
Loading…
Reference in new issue