fix: improve handling of unowned derived signals (#10342)

pull/10346/head
Dominic Gannaway 11 months ago committed by GitHub
parent 145b233041
commit 23b38a3471
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve handling of unowned derived signals

@ -623,8 +623,14 @@ function process_microtask() {
export function schedule_effect(signal, sync) {
const flags = signal.f;
if (sync) {
execute_effect(signal);
set_signal_status(signal, CLEAN);
const previously_flushing_effect = is_flushing_effect;
try {
is_flushing_effect = true;
execute_effect(signal);
set_signal_status(signal, CLEAN);
} finally {
is_flushing_effect = previously_flushing_effect;
}
} else {
if (current_scheduler_mode === FLUSH_MICROTASK) {
if (!is_micro_task_queued) {

@ -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…
Cancel
Save