fix: correctly set `is_updating` before flushing root effects (#15442)

* fix: correctly set `is_updating` before flushing root effects

* rename for consistency with update_effect

* use var

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/15445/head
Paolo Ricciuti 6 months ago committed by GitHub
parent b28b013503
commit 181fb2ad49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly set `is_updating` before flushing root effects

@ -644,8 +644,11 @@ function infinite_loop_guard() {
}
function flush_queued_root_effects() {
var was_updating_effect = is_updating_effect;
try {
var flush_count = 0;
is_updating_effect = true;
while (queued_root_effects.length > 0) {
if (flush_count++ > 1000) {
@ -670,6 +673,7 @@ function flush_queued_root_effects() {
}
} finally {
is_flushing = false;
is_updating_effect = was_updating_effect;
last_scheduled_effect = null;
if (DEV) {

@ -1135,4 +1135,45 @@ describe('signals', () => {
destroy();
};
});
test('unowned deriveds correctly update', () => {
const log: any[] = [];
return () => {
const a = state(0);
const b = state(0);
const c = derived(() => {
return $.get(a);
});
const d = derived(() => {
return $.get(b);
});
const destroy = effect_root(() => {
const e = derived(() => {
return $.get(c) === 1 && $.get(d) === 1;
});
render_effect(() => {
log.push($.get(e));
});
});
assert.deepEqual(log, [false]);
set(a, 1);
set(b, 1);
flushSync();
assert.deepEqual(log, [false, true]);
set(b, 9);
flushSync();
assert.deepEqual(log, [false, true, false]);
destroy();
};
});
});

Loading…
Cancel
Save