Repository navigation
Closed
Description
Describe the bug
I was experimenting with rendering props and found a strange behaviour.
When nesting a component with a render prop inside the <Show /> component, Solid goes into an infinite rendering loop.
I've prepared a minimal Playground demo demostrating the problem.
The issue seems to appear only when using <Show /> with a function instead of a direct component.
From the playground, this works as expected:
<Show when={showNoLoopAlt()}>
<WithRandom>{(data) => <span>{data}</span>}</WithRandom>
</Show>while this doesn't:
<Show when={showLoop()}>
{() => <WithRandom>{(data) => <span>{data}</span>}</WithRandom>}
</Show>Also, rearranging the code to make <Show /> the child component doesn't present the same problem:
<WithRandom>
{(data) => (
<Show when={showNoLoop()}>{() => <span>{data}</span>}</Show>
)}
</WithRandom>Your Example Website or App
Steps to Reproduce the Bug or Issue
- Open the Playground demo
- Click the
show (loop)button - Watch the console
Expected behavior
No infinite loop.
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Chrome
- Version: 103.0.5060.53
Additional context
No response
Activity
ryansolid commentedon Aug 8, 2022
Yeah it's because we have to support:
more specifically
Where the component returns a memo.
There is basically no difference from runtime perspective between that and what you wrote for infinite loop
I did try at one point to look at if it were a getter or not but that also has holes. So sort of stuck between supporting argument functions and not supporting:
Where something is a function.
Also worth looking at this older issue: #869
cdellacqua commentedon Aug 8, 2022
Thanks for taking the time!
Tinkering with the playground code I also tried to use different hooks other than
createComputed, but with the same result.Interestingly if the child component does not use any hook other than
createSignalthe problem seems to disappear.ryansolid commentedon Aug 8, 2022
It's just a matter of being a tracking scope being present. I'd just avoid sending argument callbacks to
<Show>at the present. It's a quirk of Show and Switch/Match. We might find a way to mitigate this at some point but that's why we are always careful to untrack things automatically because without that sort of control zone guarantee things can get out of hand quickly.I think the createComputed is just want causing the chain to happen but the over-tracking is already present at that point.
cdellacqua commentedon Aug 8, 2022
Ok, I think I get what you're saying about the tracking.
If it's fine with you, I'd leave this issue open considering this has some footgun potential.
Thanks for now!
ryansolid commentedon Aug 8, 2022
I don't think there is an easy solve. I was thinking the presence of a getter could make this an easier determination. But passing props through would be a
getter. So this is unlikely to change.
This is ambiguous. Basically render props make it so we can't detect the difference.
cdellacqua commentedon Jan 3, 2023
It seems like in recent versions of solid the problem disappeared. I guess the key change was introduced in 1.5.0 with the new batching behaviour.
I just tried to replicate the original example and it looks fine now (I had to rewrite it because the playground link is not working anymore).