@@ -118,14 +118,13 @@ export function setPendingError(el: Computed<any>, source?: Computed<any>, error
118118 if ( el . _x !== null ) el . _x . _error = null ;
119119 return ;
120120 }
121- if ( error instanceof NotReadyError && error . source === source ) {
122- ext ( el ) . _error = error ;
123- return ;
124- }
125- const current = el . _x ?. _error ;
126- if ( ! ( current instanceof NotReadyError ) || current . source !== source ) {
127- ext ( el ) . _error = new NotReadyError ( source ) ;
128- }
121+ // The given error when it names this source, else the current one when it
122+ // does (rewritten unchanged), else a fresh one.
123+ const current = error instanceof NotReadyError && error . source === source ? error : el . _x ?. _error ;
124+ ext ( el ) . _error =
125+ current instanceof NotReadyError && current . source === source
126+ ? current
127+ : new NotReadyError ( source ) ;
129128}
130129
131130export function forEachDependent (
@@ -135,6 +134,25 @@ export function forEachDependent(
135134 for ( let s = el . _subs ; s !== null ; s = s . _nextSub ) fn ( s . _sub , s ) ;
136135}
137136
137+ /** Each dependent reachable from `el`, depth first. `fn` sees every arrival,
138+ * `seen` when an earlier branch already walked the node (a diamond); the
139+ * node's dependents are walked once, on its first arrival unless `fn`
140+ * returns false (then it stays unmarked: a later branch may walk it). */
141+ function walkDependents (
142+ el : Computed < any > ,
143+ fn : ( node : Computed < any > , seen : boolean ) => unknown
144+ ) : void {
145+ const visited = new NewSet < Computed < any > > ( ) ;
146+ const visit = ( node : Computed < any > ) => {
147+ const seen = visited . has ( node ) ;
148+ if ( fn ( node , seen ) !== false && ! seen ) {
149+ visited . add ( node ) ;
150+ forEachDependent ( node , visit ) ;
151+ }
152+ } ;
153+ forEachDependent ( el , visit ) ;
154+ }
155+
138156// Queue a node to re-run on the next flush (used both when a pending source
139157// settles and when an `isPending` observer must re-evaluate after a real error):
140158// shared scheduling helper in heap.ts (tracked effects bypass the heap).
@@ -161,14 +179,9 @@ export function releaseIfSettledUnobserved(node: Computed<any>): void {
161179// Collect-then-release so unobserved() never unlinks under the walk.
162180export function releaseSettledDependents ( el : Computed < any > ) : void {
163181 let candidates : Computed < any > [ ] | undefined ;
164- const visited = new NewSet < Computed < any > > ( ) ;
165- const visit = ( node : Computed < any > ) => {
166- if ( visited . has ( node ) ) return ;
167- visited . add ( node ) ;
168- if ( ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( candidates ??= [ ] ) . push ( node ) ;
169- forEachDependent ( node , visit ) ;
170- } ;
171- forEachDependent ( el , visit ) ;
182+ walkDependents ( el , ( node , seen ) => {
183+ if ( ! seen && ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( candidates ??= [ ] ) . push ( node ) ;
184+ } ) ;
172185 if ( candidates ) for ( const node of candidates ) releaseIfSettledUnobserved ( node ) ;
173186}
174187
@@ -256,17 +269,12 @@ function stageMark(node: Computed<any>, el: Computed<any>): void {
256269
257270export function settleErroredDependents ( el : Computed < any > , error : any ) : void {
258271 let scheduled = false ;
259- const visited = new NewSet < Computed < any > > ( ) ;
260- const visit = ( node : Computed < any > ) => {
261- if ( visited . has ( node ) ) return ;
262- visited . add ( node ) ;
263- if ( node . _x ?. _error === error ) {
272+ walkDependents ( el , ( node , seen ) => {
273+ if ( ! seen && node . _x ?. _error === error ) {
264274 enqueueSub ( node ) ;
265275 scheduled = true ;
266276 }
267- forEachDependent ( node , visit ) ;
268- } ;
269- forEachDependent ( el , visit ) ;
277+ } ) ;
270278 if ( scheduled ) schedule ( ) ;
271279}
272280
@@ -334,10 +342,12 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
334342 removePendingSource ( el , source ) ;
335343 let scheduled = false ;
336344 let released : Computed < any > [ ] | undefined ;
337- const visited = new NewSet < Computed < any > > ( ) ;
338- const settle = ( node : Computed < any > ) => {
345+ walkDependents ( el , ( node , seen ) => {
339346 if (
340- visited . has ( node ) ||
347+ // A node an earlier branch settled (a diamond) takes only this early
348+ // return's verdict re-run / staged-error mark, as the walk did before
349+ // it was shared.
350+ seen ||
341351 // A conditional dropped this source, but another dependency can still
342352 // carry it. Only retire pending state inherited through the recovered
343353 // branch. Deliberately NOT marked visited on this early return: the
@@ -355,11 +365,11 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
355365 // D-41: a derivation of a staged error carries it (`stageMark`).
356366 return (
357367 holdWorkHook &&
358- ( node . _config & CONFIG_VERDICT
359- ? enqueueSub ( node )
360- : el . _config & CONFIG_STAGED_ERROR && stageMark ( node , el ) )
368+ ( node . _config & CONFIG_VERDICT
369+ ? enqueueSub ( node )
370+ : el . _config & CONFIG_STAGED_ERROR && stageMark ( node , el ) ) ,
371+ false
361372 ) ;
362- visited . add ( node ) ;
363373 node . _time = clock ;
364374 const remaining = node . _x ?. _pendingSources ?. values ( ) . next ( ) . value ;
365375 // STATUS_ERROR + pending sources only coexist via an errored loading
@@ -394,10 +404,7 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
394404 // lists this walk is still iterating.
395405 if ( ! node . _subs && node . _config & CONFIG_AUTO_DISPOSE ) ( released ??= [ ] ) . push ( node ) ;
396406 }
397- forEachDependent ( node , settle ) ;
398- } ;
399-
400- forEachDependent ( el , settle ) ;
407+ } ) ;
401408
402409 // Release before the flush schedule below: unobserved() pulls the node back
403410 // out of the heap, so the enqueueSub above never recomputes a released node.
@@ -990,34 +997,27 @@ export function notifyStatus(el: Computed<any>, status: number, error?: any): vo
990997 const pendingSource = status === STATUS_PENDING && error instanceof NotReadyError && error . source ;
991998 // (CARVE 2: the lane assignment went with the engine.)
992999
993- if ( status === STATUS_PENDING && pendingSource ) {
1000+ if ( pendingSource ) {
9941001 // D-41: a re-ask of a shown error keeps it the display (`_shownError`).
9951002 if ( el . _statusFlags & STATUS_ERROR ) el . _x ! . _shownError = el . _x ! . _error ;
9961003 addPendingSource ( el , pendingSource ) ;
997- // A re-ask of an error that answered the first read: still no value.
998- el . _statusFlags =
999- STATUS_PENDING |
1000- ( el . _statusFlags & STATUS_NO_VALUE
1004+ } else clearPendingSources ( el ) ;
1005+ // An error answering a node with no value marks it so; a re-ask of it
1006+ // (pending, from a source or not) is uninitialized again — still no
1007+ // value; a write (STATUS_NONE) gives it one.
1008+ el . _statusFlags =
1009+ status |
1010+ ( status === STATUS_ERROR
1011+ ? el . _statusFlags & ( STATUS_UNINITIALIZED | STATUS_NO_VALUE )
1012+ ? STATUS_NO_VALUE
1013+ : 0
1014+ : status === STATUS_PENDING && el . _statusFlags & STATUS_NO_VALUE
10011015 ? STATUS_UNINITIALIZED
10021016 : el . _statusFlags & STATUS_UNINITIALIZED ) ;
1003- // Preserve the current source on this propagation so readers park on
1004- // the distinct pending source.
1005- setPendingError ( el , pendingSource , error ) ;
1006- } else {
1007- clearPendingSources ( el ) ;
1008- // An error answering a node with no value marks it so; a re-ask of it
1009- // (pending) is uninitialized again; a write (STATUS_NONE) gives it one.
1010- el . _statusFlags =
1011- status |
1012- ( status === STATUS_ERROR
1013- ? el . _statusFlags & ( STATUS_UNINITIALIZED | STATUS_NO_VALUE )
1014- ? STATUS_NO_VALUE
1015- : 0
1016- : status === STATUS_PENDING && el . _statusFlags & STATUS_NO_VALUE
1017- ? STATUS_UNINITIALIZED
1018- : el . _statusFlags & STATUS_UNINITIALIZED ) ;
1019- ext ( el ) . _error = error ;
1020- }
1017+ // A propagated pending keeps its current source so readers park on the
1018+ // distinct pending source.
1019+ if ( pendingSource ) setPendingError ( el , pendingSource , error ) ;
1020+ else ext ( el ) . _error = error ;
10211021
10221022 // Lanes: a written guess is an optimistic boundary (A17 — "the optimistic
10231023 // future value until we know otherwise"). Its own source in flight is its
@@ -1098,7 +1098,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
10981098 // frame still passes through — its pass is the frame's (#3372, compiled
10991099 // shape: the unmount it stages makes the observer a zombie whose say is
11001100 // moot for this transaction, A15 #3463).
1101- if ( status === STATUS_PENDING && pendingSource && sub . _x ?. _pendingSources ?. has ( pendingSource ) ) {
1101+ if ( pendingSource && sub . _x ?. _pendingSources ?. has ( pendingSource ) ) {
11021102 if (
11031103 passLane === null &&
11041104 ( sub . _config & ( CONFIG_HELD | CONFIG_OVERRIDE ) ) === CONFIG_HELD &&
@@ -1109,7 +1109,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
11091109 return ;
11101110 }
11111111 if (
1112- ( status === STATUS_PENDING && pendingSource ) ||
1112+ pendingSource ||
11131113 ( status !== STATUS_PENDING && ( sub . _x ?. _error !== error || sub . _x ?. _pendingSources ) )
11141114 ) {
11151115 // The marked subscriber is queued for the commit sweep so its status
0 commit comments