Skip to content

Commit 7694702

Browse files
committed
perf(solid): narrowedError throws; Show/Match guards as short-circuits (#4648 review trim)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent b0319a3 commit 7694702

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎packages/solid/src/client/flow.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ type ForOptions<T> = {
3434
name?: string;
3535
};
3636

37-
const narrowedError = (name: string) =>
38-
IS_DEV
37+
const narrowedError = (name: string): never => {
38+
throw IS_DEV
3939
? `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.`
4040
: `Stale read from <${name}>.`;
41+
};
4142

4243
/**
4344
* Creates a list of elements from a list.
@@ -248,7 +249,7 @@ export function Show<T>(props: {
248249
// `latest()`-selected first mount (#3948) — while a read
249250
// after unmount sees the committed falsy and throws.
250251
// `untrack(condition)` serves neither.
251-
if (!(verdict && shown === run) && !condition()) throw narrowedError("Show");
252+
(verdict && shown === run) || condition() || narrowedError("Show");
252253
return conditionValue();
253254
}),
254255
IS_DEV && "<Show>"
@@ -342,8 +343,9 @@ export function Switch(props: { fallback?: SolidElement; children: SolidElement
342343
: untrack(
343344
() =>
344345
(child as any)(() => {
345-
if (!(verdict && shown === sel) && untrack(switchFunc)()?.[0] !== index)
346-
throw narrowedError("Match");
346+
(verdict && shown === sel) ||
347+
untrack(switchFunc)()?.[0] === index ||
348+
narrowedError("Match");
347349
return conditionValue();
348350
}),
349351
IS_DEV && "<Match>"

0 commit comments

Comments
 (0)