Skip to content

Commit 18fec5c

Browse files
committed
fix: cleanup sources in await block
1 parent 24a337a commit 18fec5c

File tree

1 file changed

+26
-4
lines changed
  • packages/svelte/src/internal/client/dom/blocks

1 file changed

+26
-4
lines changed

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
import { DEV } from 'esm-env';
33
import { is_promise } from '../../../shared/utils.js';
44
import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js';
5-
import { internal_set, mutable_source, source } from '../../reactivity/sources.js';
5+
import {
6+
internal_set,
7+
mutable_source,
8+
remove_from_legacy_sources,
9+
source
10+
} from '../../reactivity/sources.js';
611
import { flushSync, set_active_effect, set_active_reaction } from '../../runtime.js';
712
import {
813
hydrate_next,
@@ -62,6 +67,11 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
6267
var error_source = (runes ? source : mutable_source)(undefined);
6368
var resolved = false;
6469

70+
function clean_sources() {
71+
remove_from_legacy_sources(input_source);
72+
remove_from_legacy_sources(error_source);
73+
}
74+
6575
/**
6676
* @param {PENDING | THEN | CATCH} state
6777
* @param {boolean} restore
@@ -79,17 +89,29 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
7989
try {
8090
if (state === PENDING && pending_fn) {
8191
if (pending_effect) resume_effect(pending_effect);
82-
else pending_effect = branch(() => pending_fn(anchor));
92+
else
93+
pending_effect = branch(() => {
94+
pending_fn(anchor);
95+
return clean_sources;
96+
});
8397
}
8498

8599
if (state === THEN && then_fn) {
86100
if (then_effect) resume_effect(then_effect);
87-
else then_effect = branch(() => then_fn(anchor, input_source));
101+
else
102+
then_effect = branch(() => {
103+
then_fn(anchor, input_source);
104+
return clean_sources;
105+
});
88106
}
89107

90108
if (state === CATCH && catch_fn) {
91109
if (catch_effect) resume_effect(catch_effect);
92-
else catch_effect = branch(() => catch_fn(anchor, error_source));
110+
else
111+
catch_effect = branch(() => {
112+
catch_fn(anchor, error_source);
113+
return clean_sources;
114+
});
93115
}
94116

95117
if (state !== PENDING && pending_effect) {

0 commit comments

Comments
 (0)