Skip to content

Commit 7541c58

Browse files
committed
perf(signals): trim the held-error path (-52 B minified on the floor)
Truthiness checks for _shownError (always a status error when set), flushTransaction and passLane. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EBzTHZM41ipGacdiFva1ju
1 parent 0d3e82a commit 7541c58

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ export function stageError(el: Computed<any>, error: any, inPass?: boolean): boo
187187
if (
188188
!(
189189
el._config & CONFIG_HELD ||
190-
(inPass && el._flags & REACTIVE_STAGED_READ && flushTransaction !== null)
190+
(inPass && el._flags & REACTIVE_STAGED_READ && flushTransaction)
191191
) ||
192-
passLane !== null
192+
passLane
193193
)
194194
return false;
195195
// The node answered (an error ends the wait — no longer pending, nor
196196
// blocked); a shown error stays its display until the commit.
197197
clearPendingSources(el);
198-
if (el._x !== null) el._x._blocked = false;
198+
if (el._x) el._x._blocked = false;
199199
if (!((el._statusFlags &= STATUS_ERROR | STATUS_UNINITIALIZED) & STATUS_ERROR))
200200
setPendingError(el);
201201
el._pendingValue = error instanceof StatusError ? error : new StatusError(el, error);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
573573
try {
574574
valueChanged =
575575
(!isEffect && wasUninitialized) ||
576-
el._x?._shownError !== undefined ||
576+
!!el._x?._shownError ||
577577
!el._equals ||
578578
!el._equals(compareValue, value);
579579
} catch (e) {
@@ -1873,7 +1873,7 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
18731873
if (committed) return el._value as T;
18741874
// D-41: an untracked read reads the screen, and a shown error is on it
18751875
// until the answer that replaces it commits.
1876-
if (!c && el._x?._shownError !== undefined) throw el._x._shownError;
1876+
if (!c && el._x?._shownError) throw el._x._shownError;
18771877
const value = serve(el, c as Computed<any> | null) as T;
18781878
if (
18791879
!c &&
@@ -2042,7 +2042,7 @@ export function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T
20422042
// value was — the error leaves at its commit (`commitPendingNode`).
20432043
const valueChanged =
20442044
!!((el as Computed<T>)._statusFlags & STATUS_UNINITIALIZED) ||
2045-
el._x?._shownError !== undefined ||
2045+
!!el._x?._shownError ||
20462046
!el._equals ||
20472047
!el._equals(currentValue, v);
20482048
if (!valueChanged) return v;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ export function commitPendingNode(n: Signal<any>): void {
11761176
const inFlight = n._pendingValue === NOT_PENDING && (c._statusFlags! & STATUS_PENDING) !== 0;
11771177
const err = n._config & CONFIG_STAGED_ERROR;
11781178
// An answer commits: the error it replaces leaves the display (D-41).
1179-
if (!inFlight && c._x != null) c._x._shownError = undefined;
1179+
if (!inFlight && c._x) c._x._shownError = undefined;
11801180
n._config = inFlight
11811181
? (n._config & ~(CONFIG_HELD | CONFIG_HELD_FRAME)) | CONFIG_INPUTS_PUBLISHED
11821182
: n._config &

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function heldNotFinal(owner: Computed<any>): boolean {
211211
!latestActive &&
212212
!owner._x!._reask &&
213213
!(owner._statusFlags & STATUS_UNINITIALIZED) &&
214-
(owner._x!._shownError !== undefined ||
214+
(!!owner._x!._shownError ||
215215
!owner._equals ||
216216
!owner._equals(owner._value as any, owner._pendingValue as any))
217217
);

0 commit comments

Comments
 (0)