You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
<Show keyed> with a function child is not keyed when the function does not have an argument. #1508
it is expected that when passing keyed property to <Show/>
the component will be keyed, by the value of the when condition.
and that the callback will be called every time the value changes.
however solid correctly "key" a callback only if it has an argument.
need to support both a callback and a Signal Getter.
the design decision was, that a callback, is a callback only if it has an argument,
if a function without an argument is provided it is assumed to be a reactive getter / signal.
this may look like magic to the average developer but this is as intended
issue is likely going to be closed as wontfix, and maybe a better handling will come in solid 2.0 which can introduce "breaking change" to fix this.
Your Example Website or App
na
Steps to Reproduce the Bug or Issue
na
Expected behavior
it is expected that in the future solid will find a way that when keyed is provided, it assumes that a callback is provided
when the children is a function, and that the function is not a signal.
and then always call the callback when the key value changes (when={key()})
Yeah I don't believe there is anything to be done about this. I'm not even sure 2.0 has a great solution for this. In hindsight I didn't even need the callback form for this if we had keyed to begin with. Now I know TS is pretty much going to dictate this callback usage unfortunately which means there is no escaping it.
It does give keyed behavior for both scenarios where the API is being used with the parameters. The problem is that it accepts both callback and direct expression form, and in so it is only considered callback if it has an argument.
If it is only considered a callback if it has an argument isn't that the bug then since callbacks can also have no arguments? Like shouldn't the detection for signals and other things that may be confused with argumentless callbacks be refined instead, perhaps by attaching a symbol (or adding them to some special WeakSet or something else) to things that look like argumentless callbacks to tell them apart?
It could never be consistent for all cases. This at least can be explained. Consideration around the design of the Show component is less important than implication that Signals can be identified. I could see a future where maybe we could shuffle APIs around or make a different decision here on how top-level expressions could work under this case, but the decision to mark or identify signals is much more fundamental.
Oh.. you are suggesting using the fact it is an array which would isolate the change. Interesting. It adds an extra layer on every show component but it would fix this issue.
I'm in agreement with @fabiospampinato: we should not have differing behavior based on function arity here or in any other places (f.e. in createRoot), because this causes unexpected and unintuitive differences in behavior. It's a best practice to avoid it in general (not just here in Solid).
If it means we have to place a symbol on a function, or store a function in a map, or something, then that's what we have to do!
This pattern is not worth any performance gain (in case that's the reason it exists, but I'm not sure).
@trusktr the symbol on Signals or similar solutions are never adequate. They only ever solve these things in a narrow scope which is no better and is harder to explain. There are places where arity shouldn't be used (like createRoot), and likely ways to avoid it elsewhere. But the symbol is never going to be the solution.
Activity
LiQuidProQuo commentedon Jan 29, 2023
on a related note, until this is fixed / not
you should always add an argument to a callback. even if it is not needed.
if you look in this example,
<Show>in the top level of a fragment<></>gets re renderedwhen a sibling
{count()}is updated.https://playground.solidjs.com/anonymous/cc3306cb-156f-480b-bffc-7de037465602
but if we force it to be a callback by adding an argument we are safe from surprises
and only the {count()} updates not the random number in the show callback.
https://playground.solidjs.com/anonymous/80b81f6f-33c9-4469-a84c-b9f16233d1a8
LiQuidProQuo commentedon Jan 29, 2023
related / duplicate
#869
#1149
ryansolid commentedon Jan 31, 2023
Yeah I don't believe there is anything to be done about this. I'm not even sure 2.0 has a great solution for this. In hindsight I didn't even need the callback form for this if we had
keyedto begin with. Now I know TS is pretty much going to dictate this callback usage unfortunately which means there is no escaping it.fabiospampinato commentedon Jan 31, 2023
Why is this not considered a bug if asking for keyed behavior doesn't give you keyed behavior?
ryansolid commentedon Jan 31, 2023
It does give keyed behavior for both scenarios where the API is being used with the parameters. The problem is that it accepts both callback and direct expression form, and in so it is only considered callback if it has an argument.
fabiospampinato commentedon Jan 31, 2023
If it is only considered a callback if it has an argument isn't that the bug then since callbacks can also have no arguments? Like shouldn't the detection for signals and other things that may be confused with argumentless callbacks be refined instead, perhaps by attaching a symbol (or adding them to some special WeakSet or something else) to things that look like argumentless callbacks to tell them apart?
ryansolid commentedon Jan 31, 2023
It could never be consistent for all cases. This at least can be explained. Consideration around the design of the Show component is less important than implication that Signals can be identified. I could see a future where maybe we could shuffle APIs around or make a different decision here on how top-level expressions could work under this case, but the decision to mark or identify signals is much more fundamental.
fabiospampinato commentedon Jan 31, 2023
I don't understand why this can't consistently provide the user with keyed behavior, but if can't be fixed there's nothing to do I guess 👍
otonashixav commentedon Jan 31, 2023
This (argless keyed
Showspecifically) doesn't need such a heavy handed approach, cmiiw. For example changing this line to return a referentially different value would fix these issues without causing any problems afaict: https://github.com/solidjs/solid/blob/main/packages/solid/src/render/flow.ts#L113e.g. https://playground.solidjs.com/anonymous/41a887fe-47aa-4cc6-bb72-a8ddafe6eed0
ryansolid commentedon Jan 31, 2023
Oh.. you are suggesting using the fact it is an array which would isolate the change. Interesting. It adds an extra layer on every show component but it would fix this issue.
trusktr commentedon Jan 14, 2024
I'm in agreement with @fabiospampinato: we should not have differing behavior based on function arity here or in any other places (f.e. in createRoot), because this causes unexpected and unintuitive differences in behavior. It's a best practice to avoid it in general (not just here in Solid).
If it means we have to place a symbol on a function, or store a function in a map, or something, then that's what we have to do!
This pattern is not worth any performance gain (in case that's the reason it exists, but I'm not sure).
ryansolid commentedon Jan 16, 2024
@trusktr the symbol on Signals or similar solutions are never adequate. They only ever solve these things in a narrow scope which is no better and is harder to explain. There are places where arity shouldn't be used (like createRoot), and likely ways to avoid it elsewhere. But the symbol is never going to be the solution.
fix(server): Show/Switch should ignore zero-arg function children lik…