solid icon indicating copy to clipboard operation
solid copied to clipboard

boolean conditions in props should be `memo` for any dynamic expression not just function calls.

Open mizulu opened this issue 6 months ago • 0 comments

The optimization only apply when there is a function call

count()>1 && Date.now()            // Memo
count()> 1 ? Date.now()  : "B"     // Memo 
count()> 1 ? "A" : "B"             // No Memo 

but interestingly does not memo when using a getter ( :bug: ) https://playground.solidjs.com/anonymous/6afa6081-5fa7-4ca6-b690-fcb92dbbe2e0

count()>1 ? props.a : props.b

@ryansolid

I think originally I was looking at this for components.. and since components were just function calls that's how I set the rule. To be fair it's a single option switch to have it wrap getters. I think it makes sense to wrap getters as well. This was probably overlooked initially and just stayed.

Originally posted by @mizulu in #2479

created this issue so this is not lost in the other issue.

Note: the issue originally refer to boolean condition passed in props.

but this optimization also exists in JSX

This will get a memo on the condition

<b>{count()<=3 ? props.f1() : props.f2() }</b>

but this will not

<b>{count()<=3 ? props.g1 : props.g2 }</b>

there might be same expectations here too.

mizulu avatar May 29 '25 18:05 mizulu