solid icon indicating copy to clipboard operation
solid copied to clipboard

Updating onchange causes sibling to mount/unmount

Open mattbdc opened this issue 2 years ago • 1 comments

Describe the bug

https://playground.solidjs.com/anonymous/551fc377-eef8-4688-a32e-d136eb295d83

Weather updating onchange is a good idea, or even supported, in my case a bug where by untrack wasn't used at the callsite, it is still strange to see LogComponent which is an unrelated sibling, mount and unmount each time the tickTocktick signal is updated.

Your Example Website or App

https://playground.solidjs.com/anonymous/551fc377-eef8-4688-a32e-d136eb295d83

Steps to Reproduce the Bug or Issue

Run playground see unrelated component mount and unmount on each signal (although its not dependent on that signal)

Expected behavior

Not sure, but not this

Screenshots or Videos

No response

Platform

Latest

Additional context

No response

mattbdc avatar May 28 '23 02:05 mattbdc

As event handlers aren't tracked the function call is being tracked by the parent scope. Which would result in exactly what you see. Intentionally so. That's how Solid renders by nesting reactive contexts.

This is interesting case in that I can see why that wouldn't be desirable it is also not a really detectable error. The compiler I suppose could untrack in this specific case. It could also support dynamic event handlers, although that de-opts the super common case (props.onClick) when calling it yourself would be more performant. But admittedly the fact it isn't obvious that this is an error is more problematic than the fact that this is not allowed. This is definitely a place that could use improvement.

If we had a strict mode, we could make this an untrack that warned on access. That's probably the best solution outside of measuring the comparable overhead of dynamic event addition/removal.

Short term response is that dynamic event handlers aren't supported (https://www.solidjs.com/docs/latest/api#on___). But I think this definitely should be a consideration around good error message handling.

ryansolid avatar May 31 '23 09:05 ryansolid