solid
solid copied to clipboard
Effects that dispose their owner can continue to fire
Describe the bug
An effect which calls dispose of its owning root will continue to fire if onCleanup in the same root accesses something reactive.
Your Example Website or App
https://playground.solidjs.com/?hash=-963043878&version=1.4.1
Steps to Reproduce the Bug or Issue
- Click the button once.
- Click the button again and look at the console, previous effects which should be dispose will still fire.
- Continue clicking and the effects will keep stacking up.
Expected behavior
I would expect what I do in the onCleanup function not to affect disposal.
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Vivaldi/Firefox
Additional context
The problem can be avoided by untracking in the cleanup, or delaying the disposal in the effect through something like queueMicrotask.
Oh interesting. I guess we aren't untracking onCleanup we should. Actually its more than that since createRoot isn't necessarily tracked.. Oh actually it's more than that. The onCleanup already isn't under a tracked context.
the cleanup callback has the same owner as the effect the dispose() was called from

untracked cleanup, works for that use case https://playground.solidjs.com/?hash=-371961240&version=1.4.1
or calling dispose not in the effect. https://playground.solidjs.com/?hash=-1477293559&version=1.4.1