solid icon indicating copy to clipboard operation
solid copied to clipboard

Effects that dispose their owner can continue to fire

Open Bubz43 opened this issue 3 years ago • 2 comments

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

  1. Click the button once.
  2. Click the button again and look at the console, previous effects which should be dispose will still fire.
  3. 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.

Bubz43 avatar Aug 09 '22 02:08 Bubz43

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.

ryansolid avatar Aug 09 '22 02:08 ryansolid

the cleanup callback has the same owner as the effect the dispose() was called from image

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

LiQuidProQuo avatar Aug 09 '22 02:08 LiQuidProQuo