Skip to content

Commit

Permalink
Fixes <Show> evaluating the condition twice
Browse files Browse the repository at this point in the history
Adds another memo directly on `when` in `<Show>`.

solidjs#2406
  • Loading branch information
TPReal committed Jan 24, 2025
1 parent 5bc544c commit c0cc51f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/solid/src/render/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,23 @@ export function Show<T>(props: {
children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element);
}): JSX.Element {
const keyed = props.keyed;
const condition = createMemo<T | undefined | null | boolean>(
const conditionValue = createMemo<T | undefined | null | boolean>(
() => props.when,
undefined,
IS_DEV
? {
equals: (a, b) => (keyed ? a === b : !a === !b),
name: "condition"
}
: { equals: (a, b) => (keyed ? a === b : !a === !b) }
IS_DEV ? { name: "condition value" } : undefined
);
const condition = keyed
? conditionValue
: createMemo(
conditionValue,
undefined,
IS_DEV
? {
equals: (a, b) => !a === !b,
name: "condition"
}
: { equals: (a, b) => !a === !b }
);
return createMemo(
() => {
const c = condition();
Expand All @@ -129,7 +136,7 @@ export function Show<T>(props: {
? (c as T)
: () => {
if (!untrack(condition)) throw narrowedError("Show");
return props.when;
return conditionValue();
}
)
)
Expand Down

0 comments on commit c0cc51f

Please sign in to comment.