solid icon indicating copy to clipboard operation
solid copied to clipboard

`spread()` doesn't use the `children` property when an `Accessor` is passed

Open AFatNiBBa opened this issue 1 year ago • 4 comments

Describe the bug

The type definition of the spread() function states that it also accepts a function that returns an object instead of the object itself, but here it doesn't check if props is a function when accessing the children property. After checking with the playground, it seems that no property works

Your Example Website or App

https://playground.solidjs.com/anonymous/8afd997e-2827-47bf-b670-bcfbd3825315

Steps to Reproduce the Bug or Issue

Just look at the output:

  • "This works" is visible
  • "This doesn't" should be visible but isn't

Expected behavior

It should get the properties from the returned object if props is a function OR the type definition should be made to match the actual behaviour by disallowing Accessors

Screenshots or Videos

No response

Platform

  • OS: Windows 11
  • Browser: Edge 129.0.2792.89
  • Version: 1.9.2

Additional context

May be related to #1296

AFatNiBBa avatar Oct 18 '24 08:10 AFatNiBBa

99% this is a types issue. We use this internally where everything is getters. We don't special case functions here I believe. But it probably is worth double checking.

ryansolid avatar Oct 18 '24 18:10 ryansolid

I remember where <div {...func} /> and <div {...func()} /> compiled to the same code and stopped working at some point which is https://github.com/ryansolid/dom-expressions/commit/12e84da9b11ad7ec6bf89a93472b76828486fde0. As children, ref is handled separately from the rest of the props, spread can't accept accessor anymore so the compiler assists by wrapping with mergeProps to turn it into getter object. But children can still be a getter or an accessor though.

After that commit https://github.com/solidjs/solid/releases/tag/v1.6.0 happened.

mdynnl avatar Oct 18 '24 20:10 mdynnl

(Just to be clear: In my code I have absolutely no need to pass an Accessor to spread(), I just ran into the problem)

AFatNiBBa avatar Oct 19 '24 13:10 AFatNiBBa

It should get the properties from the returned object if ...

Right, I missed this section.

I just ran into the problem

Not clear what this means though. Is it some external/internal code or a template that outputs this?

mdynnl avatar Oct 19 '24 15:10 mdynnl

Not clear what this means though. Is it some external/internal code or a template that outputs this?

I just tried to use the function as an experiment

AFatNiBBa avatar Oct 20 '24 18:10 AFatNiBBa

Thanks @mdynnl I think you are correct. I realized that spread as a function was insufficient and changed to only accepting objects. So I think that confirms it is a types thing.

ryansolid avatar Oct 21 '24 17:10 ryansolid

I updated the types so this should be fixed by now.

ryansolid avatar Apr 30 '25 20:04 ryansolid