@@ -59,7 +59,7 @@ import {
5959 STATUS_UNINITIALIZED
6060} from "./constants.js" ;
6161import { attrHooks } from "./attribution-hooks.js" ;
62- import { creatorReads , ext , stagedRead , tracking } from "./core.js" ;
62+ import { bornInto , creatorReads , ext , stagedRead , tracking } from "./core.js" ;
6363import { NotReadyError } from "./error.js" ;
6464import { removePendingSource } from "./async.js" ;
6565import { laneValueOf } from "./truth.js" ;
@@ -75,6 +75,7 @@ import {
7575 joinFuture ,
7676 laneDirty ,
7777 list ,
78+ stagedReaders ,
7879 staleReader ,
7980 merge ,
8081 newTransaction ,
@@ -509,6 +510,8 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
509510 l . _verdict = null ;
510511 if ( lanes . indexOf ( v ) !== - 1 ) dissolveLane ( v , null ) ;
511512 }
513+ // First loads this dissolution leaves loading (below).
514+ const loading : Computed < any > [ ] = [ ] ;
512515 for ( let i = 0 ; i < l . _nodes . length ; i ++ ) {
513516 const n = l . _nodes [ i ] ;
514517 const x = n . _x ! ;
@@ -544,8 +547,20 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
544547 // lane's answer beside inputs that are the truth now: a fresh reader
545548 // of its flight observes it (#3648, #3651; #3305's commit beneath a
546549 // flight).
550+ // Not a first load the lane produced nothing for whose own flight is
551+ // up, nor one pending on such a load kept here (an identity memo of
552+ // it, a derived store's derive): committing its empty `_value` would
553+ // initialize it as `undefined`, which `latest()` would serve and
554+ // `isPending()` call pending. It stays loading until its flight
555+ // answers (D-22, A19 exc. 1; async-gen 3289 #929, 91501 #504, #156).
547556 x . _transaction = null ;
548- if ( ! effect && ! guess ) n . _pendingValue = latest ;
557+ if ( ! effect && ! guess )
558+ slot === NOT_PENDING &&
559+ ( ( n as Computed < any > ) . _statusFlags & ( STATUS_UNINITIALIZED | STATUS_PENDING ) ) ===
560+ ( STATUS_UNINITIALIZED | STATUS_PENDING ) &&
561+ ( x . _inFlight || loading . some ( q => x . _pendingSources ?. has ( q ) ) )
562+ ? loading . push ( n as Computed < any > )
563+ : ( n . _pendingValue = latest ) ;
549564 commitPendingNode ( n ) ;
550565 if ( ! effect ) {
551566 if (
@@ -927,17 +942,22 @@ const applyGuessesAt = (parent: Transaction | null): void => {
927942 judged = lanes . length ;
928943 if ( pendingGuesses . length !== 0 ) applyGuesses ( parent ) ;
929944} ;
930- const laneSeams = ( leaks : Computed < any > [ ] | null ) : void => {
945+ const laneSeams = ( t : Transaction | null ) : void => {
931946 // Passes that read a write the parked frame holds as the screen
932947 // (`stagedReaders`: lane work, a verdict reader before the verdict): they
933948 // re-derive on the committed world next round (and register as stale
934949 // readers of the transaction there); a lane's runs wait that round — a
935950 // lane sees the screen plus its own guesses.
936951 const leaked : Transaction [ ] = [ ] ;
937- if ( leaks !== null )
938- for ( let i = 0 ; i < leaks . length ; i ++ ) {
939- const r = leaks [ i ] ;
940- const l = r . _x ?. _transaction ;
952+ if ( t !== null )
953+ for ( let i = 0 ; i < stagedReaders . length ; i ++ ) {
954+ const r = stagedReaders [ i ] ,
955+ // A pass no transaction holds that read the frame's staging (an
956+ // effect, a `[s(), latest(s)]` reader watched before the frame had
957+ // a transaction): judged by the frame's — it re-derives only if the
958+ // frame stays parked; landing here, what it read is the screen (one
959+ // run, D-22).
960+ l = r . _x ?. _transaction || ( r . _flags & REACTIVE_STAGED_READ ? t : null ) ;
941961 // A verdict reader a later read of the same pass routed into a verdict
942962 // lane answered for itself: it re-derives at the holder's landing, not
943963 // now (one run — #3322, #3540). Other verdict-lane work re-derives only
@@ -947,15 +967,23 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
947967 // flight, held as the frame's pending observer or its staged
948968 // derivation) has nothing to re-derive: its re-run re-enters that
949969 // transaction and parks it again, every round — it runs at the
950- // landing (#4349).
970+ // landing (#4349). One that read a staging re-derives only if its
971+ // frame stays parked: landing at this seam, what it read is the screen
972+ // (one run, D-22). Not one born into that frame (a held pass's child,
973+ // ruling A): it has no screen, its reads are the transaction's either
974+ // way — it runs again at the landing, not now.
951975 if (
952976 r . _flags & REACTIVE_DISPOSED ||
953977 ( l ?. _lane
954978 ? l . _parent ?. _verdict === l &&
955979 ( r . _config & CONFIG_VERDICT
956980 ? ! ( r . _flags & REACTIVE_PROBE_UNANSWERED )
957981 : ! blocked ( l . _parent ) )
958- : l && ! ( r . _flags & ( REACTIVE_STAGED_READ | REACTIVE_PROBE_UNANSWERED ) ) )
982+ : l &&
983+ ! (
984+ r . _flags & REACTIVE_PROBE_UNANSWERED ||
985+ ( r . _flags & REACTIVE_STAGED_READ && blocked ( l ) && ! bornInto ( r , l ) )
986+ ) )
959987 )
960988 continue ;
961989 // A leaked effect re-derives seated in its lane from its first read: it
@@ -968,8 +996,12 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
968996 enqueueSub ( r ) ;
969997 if ( l ?. _lane && leaked . indexOf ( l ) === - 1 ) leaked . push ( l ) ;
970998 }
971- for ( let k = Math . min ( judged , lanes . length ) - 1 ; k >= 0 ; k -- )
972- laneSeam ( lanes [ k ] , leaked . indexOf ( lanes [ k ] ) !== - 1 ) ;
999+ // A verdict lane born at this seam is judged with it: it exists only once
1000+ // a pass routed into it — the park seam's zombie verdict readers re-run
1001+ // as its work so that this seam reveals them (#3444).
1002+ for ( let k = lanes . length - 1 ; k >= 0 ; k -- )
1003+ if ( k < judged || lanes [ k ] . _parent ?. _verdict === lanes [ k ] )
1004+ laneSeam ( lanes [ k ] , leaked . indexOf ( lanes [ k ] ) !== - 1 ) ;
9731005 // A verdict reader that entered a lane this seam held: its run waits with
9741006 // the lane, and the verdict beside it would freeze — it re-derives next
9751007 // round from the frame's seat, a stale reader of the lane (#4284).
0 commit comments