fix: ensure deferred effects are properly revived after async operations (fixes #17304)

pull/17307/head
harshitydv1 2 days ago
parent 0cdc431562
commit 04b686b241

@ -0,0 +1,7 @@
---
'svelte': patch
---
fix: ensure deferred effects are properly revived after async operations (fixes #17304)
When using `async` in SvelteKit with preloading data (via `data-sveltekit-preload-data` or `preloadData()`), `$effect` callbacks were not firing even though values were updating. This was because when forks are committed (which SvelteKit's preload uses), the `revive()` method wasn't ensuring the batch was properly activated before scheduling deferred effects. This fix ensures the batch context is correct when reviving effects.

@ -483,6 +483,13 @@ export class Batch {
}
revive() {
// Ensure the batch is active before scheduling effects
// This is critical for fork commits (used by SvelteKit's preload)
var was_current = current_batch === this;
if (!was_current) {
this.activate();
}
for (const e of this.#dirty_effects) {
set_signal_status(e, DIRTY);
schedule_effect(e);
@ -496,7 +503,14 @@ export class Batch {
this.#dirty_effects = [];
this.#maybe_dirty_effects = [];
this.flush();
// Always flush if we have pending work that needs to be resolved
if (this.#pending === 0 || queued_root_effects.length > 0) {
this.flush();
}
if (!was_current) {
this.deactivate();
}
}
/** @param {() => void} fn */

Loading…
Cancel
Save