@@ -120,14 +120,13 @@ export function setPendingError(el: Computed<any>, source?: Computed<any>, error
120120 if ( el . _x !== null ) el . _x . _error = null ;
121121 return ;
122122 }
123- if ( error instanceof NotReadyError && error . source === source ) {
124- ext ( el ) . _error = error ;
125- return ;
126- }
127- const current = el . _x ?. _error ;
128- if ( ! ( current instanceof NotReadyError ) || current . source !== source ) {
129- ext ( el ) . _error = new NotReadyError ( source ) ;
130- }
123+ // The given error when it names this source, else the current one when it
124+ // does (rewritten unchanged), else a fresh one.
125+ const current = error instanceof NotReadyError && error . source === source ? error : el . _x ?. _error ;
126+ ext ( el ) . _error =
127+ current instanceof NotReadyError && current . source === source
128+ ? current
129+ : new NotReadyError ( source ) ;
131130}
132131
133132export function forEachDependent (
@@ -137,6 +136,25 @@ export function forEachDependent(
137136 for ( let s = el . _subs ; s !== null ; s = s . _nextSub ) fn ( s . _sub , s ) ;
138137}
139138
139+ /** Each dependent reachable from `el`, depth first. `fn` sees every arrival,
140+ * `seen` when an earlier branch already walked the node (a diamond); the
141+ * node's dependents are walked once, on its first arrival unless `fn`
142+ * returns false (then it stays unmarked: a later branch may walk it). */
143+ function walkDependents (
144+ el : Computed < any > ,
145+ fn : ( node : Computed < any > , seen : boolean ) => unknown
146+ ) : void {
147+ const visited = new NewSet < Computed < any > > ( ) ;
148+ const visit = ( node : Computed < any > ) => {
149+ const seen = visited . has ( node ) ;
150+ if ( fn ( node , seen ) !== false && ! seen ) {
151+ visited . add ( node ) ;
152+ forEachDependent ( node , visit ) ;
153+ }
154+ } ;
155+ forEachDependent ( el , visit ) ;
156+ }
157+
140158// Queue a node to re-run on the next flush (used both when a pending source
141159// settles and when an `isPending` observer must re-evaluate after a real error):
142160// shared scheduling helper in heap.ts (tracked effects bypass the heap).
@@ -169,14 +187,9 @@ export function releaseIfSettledUnobserved(node: Computed<any>): void {
169187// Collect-then-release so unobserved() never unlinks under the walk.
170188export function releaseSettledDependents ( el : Computed < any > ) : void {
171189 let candidates : Computed < any > [ ] | undefined ;
172- const visited = new NewSet < Computed < any > > ( ) ;
173- const visit = ( node : Computed < any > ) => {
174- if ( visited . has ( node ) ) return ;
175- visited . add ( node ) ;
176- if ( ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( candidates ??= [ ] ) . push ( node ) ;
177- forEachDependent ( node , visit ) ;
178- } ;
179- forEachDependent ( el , visit ) ;
190+ walkDependents ( el , ( node , seen ) => {
191+ if ( ! seen && ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( candidates ??= [ ] ) . push ( node ) ;
192+ } ) ;
180193 if ( candidates ) for ( const node of candidates ) releaseIfSettledUnobserved ( node ) ;
181194}
182195
@@ -264,17 +277,12 @@ function stageMark(node: Computed<any>, el: Computed<any>): void {
264277
265278export function settleErroredDependents ( el : Computed < any > , error : any ) : void {
266279 let scheduled = false ;
267- const visited = new NewSet < Computed < any > > ( ) ;
268- const visit = ( node : Computed < any > ) => {
269- if ( visited . has ( node ) ) return ;
270- visited . add ( node ) ;
271- if ( node . _x ?. _error === error ) {
280+ walkDependents ( el , ( node , seen ) => {
281+ if ( ! seen && node . _x ?. _error === error ) {
272282 enqueueSub ( node ) ;
273283 scheduled = true ;
274284 }
275- forEachDependent ( node , visit ) ;
276- } ;
277- forEachDependent ( el , visit ) ;
285+ } ) ;
278286 if ( scheduled ) schedule ( ) ;
279287}
280288
@@ -342,10 +350,12 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
342350 removePendingSource ( el , source ) ;
343351 let scheduled = false ;
344352 let released : Computed < any > [ ] | undefined ;
345- const visited = new NewSet < Computed < any > > ( ) ;
346- const settle = ( node : Computed < any > ) => {
353+ walkDependents ( el , ( node , seen ) => {
347354 if (
348- visited . has ( node ) ||
355+ // A node an earlier branch settled (a diamond) takes only this early
356+ // return's verdict re-run / staged-error mark, as the walk did before
357+ // it was shared.
358+ seen ||
349359 // A conditional dropped this source, but another dependency can still
350360 // carry it. Only retire pending state inherited through the recovered
351361 // branch. Deliberately NOT marked visited on this early return: the
@@ -363,11 +373,11 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
363373 // D-41: a derivation of a staged error carries it (`stageMark`).
364374 return (
365375 holdWorkHook &&
366- ( node . _config & CONFIG_VERDICT
367- ? enqueueSub ( node )
368- : el . _config & CONFIG_STAGED_ERROR && stageMark ( node , el ) )
376+ ( node . _config & CONFIG_VERDICT
377+ ? enqueueSub ( node )
378+ : el . _config & CONFIG_STAGED_ERROR && stageMark ( node , el ) ) ,
379+ false
369380 ) ;
370- visited . add ( node ) ;
371381 node . _time = clock ;
372382 const remaining = node . _x ?. _pendingSources ?. values ( ) . next ( ) . value ;
373383 // STATUS_ERROR + pending sources only coexist via an errored loading
@@ -402,10 +412,7 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
402412 // lists this walk is still iterating.
403413 if ( ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( released ??= [ ] ) . push ( node ) ;
404414 }
405- forEachDependent ( node , settle ) ;
406- } ;
407-
408- forEachDependent ( el , settle ) ;
415+ } ) ;
409416
410417 // A node the enqueueSub above queued is released at that pass's tail
411418 // (`releaseIfSettledUnobserved`, REACTIVE_RELEASE_AFTER): the landing's
@@ -1000,34 +1007,27 @@ export function notifyStatus(el: Computed<any>, status: number, error?: any): vo
10001007 const pendingSource = status === STATUS_PENDING && error instanceof NotReadyError && error . source ;
10011008 // (CARVE 2: the lane assignment went with the engine.)
10021009
1003- if ( status === STATUS_PENDING && pendingSource ) {
1010+ if ( pendingSource ) {
10041011 // D-41: a re-ask of a shown error keeps it the display (`_shownError`).
10051012 if ( el . _statusFlags & STATUS_ERROR ) el . _x ! . _shownError = el . _x ! . _error ;
10061013 addPendingSource ( el , pendingSource ) ;
1007- // A re-ask of an error that answered the first read: still no value.
1008- el . _statusFlags =
1009- STATUS_PENDING |
1010- ( el . _statusFlags & STATUS_NO_VALUE
1014+ } else clearPendingSources ( el ) ;
1015+ // An error answering a node with no value marks it so; a re-ask of it
1016+ // (pending, from a source or not) is uninitialized again — still no
1017+ // value; a write (STATUS_NONE) gives it one.
1018+ el . _statusFlags =
1019+ status |
1020+ ( status === STATUS_ERROR
1021+ ? el . _statusFlags & ( STATUS_UNINITIALIZED | STATUS_NO_VALUE )
1022+ ? STATUS_NO_VALUE
1023+ : 0
1024+ : status === STATUS_PENDING && el . _statusFlags & STATUS_NO_VALUE
10111025 ? STATUS_UNINITIALIZED
10121026 : el . _statusFlags & STATUS_UNINITIALIZED ) ;
1013- // Preserve the current source on this propagation so readers park on
1014- // the distinct pending source.
1015- setPendingError ( el , pendingSource , error ) ;
1016- } else {
1017- clearPendingSources ( el ) ;
1018- // An error answering a node with no value marks it so; a re-ask of it
1019- // (pending) is uninitialized again; a write (STATUS_NONE) gives it one.
1020- el . _statusFlags =
1021- status |
1022- ( status === STATUS_ERROR
1023- ? el . _statusFlags & ( STATUS_UNINITIALIZED | STATUS_NO_VALUE )
1024- ? STATUS_NO_VALUE
1025- : 0
1026- : status === STATUS_PENDING && el . _statusFlags & STATUS_NO_VALUE
1027- ? STATUS_UNINITIALIZED
1028- : el . _statusFlags & STATUS_UNINITIALIZED ) ;
1029- ext ( el ) . _error = error ;
1030- }
1027+ // A propagated pending keeps its current source so readers park on the
1028+ // distinct pending source.
1029+ if ( pendingSource ) setPendingError ( el , pendingSource , error ) ;
1030+ else ext ( el ) . _error = error ;
10311031
10321032 // Lanes: a written guess is an optimistic boundary (A17 — "the optimistic
10331033 // future value until we know otherwise"). Its own source in flight is its
@@ -1108,7 +1108,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
11081108 // frame still passes through — its pass is the frame's (#3372, compiled
11091109 // shape: the unmount it stages makes the observer a zombie whose say is
11101110 // moot for this transaction, A15 #3463).
1111- if ( status === STATUS_PENDING && pendingSource && sub . _x ?. _pendingSources ?. has ( pendingSource ) ) {
1111+ if ( pendingSource && sub . _x ?. _pendingSources ?. has ( pendingSource ) ) {
11121112 if (
11131113 passLane === null &&
11141114 ( sub . _config & ( CONFIG_HELD | CONFIG_OVERRIDE ) ) === CONFIG_HELD &&
@@ -1119,7 +1119,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
11191119 return ;
11201120 }
11211121 if (
1122- ( status === STATUS_PENDING && pendingSource ) ||
1122+ pendingSource ||
11231123 ( status !== STATUS_PENDING && ( sub . _x ?. _error !== error || sub . _x ?. _pendingSources ) )
11241124 ) {
11251125 // The marked subscriber is queued for the commit sweep so its status
0 commit comments