solid icon indicating copy to clipboard operation
solid copied to clipboard

Batch top level effects to make them behave consistent with regular effects

Open titoBouzout opened this issue 1 year ago • 1 comments

Describe the bug

Top level effects (createEffect that isn't wrapped in a createRoot) behave inconsistently when compared with effects under a root, because top level effects aren't batched.

This isn't an issue with solid per se, as its render function already wraps in a root.

The issue is when solid is used for reactivity exclusively(besides rendering dom nodes), such when creating long-lived effects that will never be disposed, reactivity in the server; or for demo purposes (such playground snippets and the like), this inconsistency gets in the way because doesn't match expectations, it could be hard to understand why does behave this way.

It is possible that batching top level effects improve the performance of these effects.

Your Example Website or App

meaw

Steps to Reproduce the Bug or Issue

Top level effect non batched https://playground.solidjs.com/anonymous/39d404d1-5c4a-411b-ab85-f915c82089e6

behaves differently to:

effect wrapped in a root https://playground.solidjs.com/anonymous/d30de401-fc16-4c9a-a247-39333b970b8b behaves the same as a top level effect that uses batch https://playground.solidjs.com/anonymous/13b29236-c0f9-46fb-8b20-4a221fa9e4df

Expected behavior

Please batch top level effects.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

As discussed on discord, it may be about changing this line https://github.com/solidjs/solid/blob/main/packages/solid/src/reactive/signal.ts#L357

titoBouzout avatar Mar 21 '24 23:03 titoBouzout

I'm still very tempted not to touch anything here until 2.0. Just because of behavior changes.

ryansolid avatar Apr 22 '24 17:04 ryansolid