vide icon indicating copy to clipboard operation
vide copied to clipboard

`show` uses a truthy source, but doesn't accept a primtive nil.

Open TaylorsRus opened this issue 7 months ago • 2 comments

show will error if you pass nil to the first arg. To combat this, you must pass Source or Source(nil).

While not accepting a primtive non-nil value is valid due to the type checkers limitations- I think show should accept nil, to improve DX by reducing bloat props, for example, prop Selected may be true or false, but you can pass a falsy value by passing no prop at all, so prop.Selected == nil, which you can then pass into show.

TaylorsRus avatar May 03 '25 19:05 TaylorsRus

Is your prop's type specifically boolean? or can it be a source? When conditionally rendering based on a non-reactive value (i.e. the condition is boolean? and not boolean? | () -> boolean), you should instead use an if-else expression or another equivalent:

create("Frame", {
    if condition then create("Frame", {}) else nil,
})

create("Frame", {
    condition and create("Frame", {}) or nil,
})

If the condition is (() -> boolean)?, this can also be extended to show():

create("Frame", {
    condition and show(condition, function(condition)
        return create("Frame", {})
    end)
})

littensy avatar May 03 '25 19:05 littensy

In this specific use case which brought the problem to my attention- it's a source value, so just (() -> boolean)? is the type; I am aware of the various if else conditions that can get around this, so the problem is more about QOL, also not sure how re-evaluations are effected by these checks

Specific use case: Image

TaylorsRus avatar May 03 '25 20:05 TaylorsRus