Skip to content

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

Open
@mizulu

Description

@mizulu

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 ( 🐛 )
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions