-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
It looks like the when condition of the <Show> component is run twice unnecessarily at initialisation when a function as passed as children. It is first run when creating the condition memo, but then it is run again to be passed as the parameter to the children func, instead of passing the condition directly to the children func.
Your Example Website or App
https://stackblitz.com/edit/solidjs-templates-blqgxpec?file=src%2FApp.tsx
Steps to Reproduce the Bug or Issue
- Use a
<Show>component (notkeyed), with function passed as children.
The when condition is immediately evaluated twice.
Expected behavior
The when expression is evaluated once, and then reevaluated whenever there's an update notifying the value might have changed.
Screenshots or Videos
No response
Platform
- OS: Windows
- Browser: Chrome
- Version: 1.7.6
Additional context
The problem is especially big if the condition creates some JSX, e.g. when JSX is passed through props. Normally this JSX is not considered to change, even if some signals are updated, but rather it updates its contents reactively, but here two instances of the JSX are created, and the first one is not cleaned up when the second one is created, but instead they coexist (although only one of them is mounted to the document). See the provided stackblitz for an example.
The Show component has this code:
(child as any)(
keyed ? (c as T) : () => {
if (!untrack(condition)) throw narrowedError("Show");
return props.when;
}
)It is surprising to me that props.when is passed to child, instead of passing there the already memoised condition created before. This would fix the problem described here, but I'm not able to guess if it creates any other problems.