22import { DEV } from 'esm-env' ;
33import { is_promise } from '../../../shared/utils.js' ;
44import { 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' ;
611import { flushSync , set_active_effect , set_active_reaction } from '../../runtime.js' ;
712import {
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