Skip to content

Commit 98d457f

Browse files
refactor(signals): fold the reveal-hold check into the existing actualError branch
Same semantics, fewer bytes: the new check and the reporter registration share one actualError test, read the module-level currentBatch instead of this._batch, and the error fallback is `??` (every caller passes nothing or this node's own _x._error, so a null falls back to the same null). Measured against next: signals + createStore 14358 B brotli, under both the cap and the pre-PR baseline; the PR as written was 18 B over on Linux. Co-authored-by: Cursor <[email protected]>
1 parent f98bd77 commit 98d457f

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -749,36 +749,36 @@ export class GlobalQueue extends Queue {
749749
// Only track async if the boundary is propagating STATUS_PENDING (not caught by boundary)
750750
if (mask & STATUS_PENDING) {
751751
if (flags & STATUS_PENDING) {
752-
const actualError = error !== undefined ? error : node._x?._error;
752+
// Callers pass either nothing or this node's own `_x._error`, so `??`
753+
// is exact (a null error falls back to the same null).
754+
const actualError = error ?? node._x?._error;
753755
// A visibility-only mark notification (the affects() boundary
754756
// channel) updates display state on its way up but must be invisible
755757
// to completion accounting BY CONSTRUCTION: it never registers a
756758
// reporter and never counts toward the loading-boundary diagnostic.
757759
if ((actualError as NotReadyError)?._markVisual) return true;
758-
// A reveal can discover a flight started in an earlier flush. Hold the
759-
// staged writes with that reader (A15), even if the reader is new.
760-
// Fresh/reset loading boundaries consume pending before it reaches here.
761-
// A reader already parked in a transition must not open a second one.
762-
if (
763-
!activeTransition &&
764-
!node._transition &&
765-
actualError &&
766-
this._batch._pendingNodes.length
767-
)
768-
this.initTransition();
769-
if (activeTransition && actualError) {
770-
const source = (actualError as NotReadyError).source;
771-
// The one sanctioned registration site (INV-3): async blockers only
772-
// enter the transition from queue notification.
773-
if (__DEV__) beginAsyncReporterWrites();
774-
let reporters = activeTransition._asyncReporters.get(source);
775-
if (!reporters) activeTransition._asyncReporters.set(source, (reporters = new Set()));
776-
if (__DEV__) endAsyncReporterWrites();
777-
const prevSize = reporters.size;
778-
reporters.add(node);
779-
if (reporters.size !== prevSize) {
780-
schedule();
781-
GlobalQueue._wakeSuppressedProbes?.(activeTransition);
760+
if (actualError) {
761+
// A reveal can discover a flight started in an earlier flush. Hold
762+
// the staged writes with that reader (A15), even if the reader is
763+
// new. Fresh/reset loading boundaries consume pending before it
764+
// reaches here. A reader already parked in a transition must not
765+
// open a second one.
766+
if (!activeTransition && !node._transition && currentBatch._pendingNodes.length)
767+
this.initTransition();
768+
if (activeTransition) {
769+
const source = (actualError as NotReadyError).source;
770+
// The one sanctioned registration site (INV-3): async blockers only
771+
// enter the transition from queue notification.
772+
if (__DEV__) beginAsyncReporterWrites();
773+
let reporters = activeTransition._asyncReporters.get(source);
774+
if (!reporters) activeTransition._asyncReporters.set(source, (reporters = new Set()));
775+
if (__DEV__) endAsyncReporterWrites();
776+
const prevSize = reporters.size;
777+
reporters.add(node);
778+
if (reporters.size !== prevSize) {
779+
schedule();
780+
GlobalQueue._wakeSuppressedProbes?.(activeTransition);
781+
}
782782
}
783783
}
784784
if (__DEV__ && _enforceLoadingBoundary) _hitUnhandledAsync = true;

0 commit comments

Comments
 (0)