-
-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement immediate/synchronous effects #2822
Comments
I have a use-case that would benefit from this. I am building a custom renderer where the data is owned externally from leptos, therefore I need to be able to know when leptos wants access to this data so I can pause other processes and make that data available. Maybe another solution that would work for me is being able to manage the async effects myself, i.e. implementing an |
I'm curious if you've looked at something like |
Hmmm I know of it but I didn't think about it. The effects I'm having trouble with are produced internally by leptons (I think to update the renderer). I'll see if there's a way I can make it use RenderEffect instead. Update: It is using Callstack
Edit 2: I was able to implement a |
Is your feature request related to a problem? Please describe.
0.7 changes effect scheduling to automatically batch effects, and to run them asynchronously, as determined by whichever async runtime is being used. In the default web case, this is
wasm-bindgen-futures
, which usesqueueMicrotask
. In other words, updating a signal updates its value immediately, but runs effects on the next microtask. This means that an effect does not run immediately, once per signal change.In general, this is good, because effects are intended to synchronize the current/latest value of a signal with the outside world in some way that is typically orders of magnitude more expensive than actually updating the signal: for example, updating a DOM node.
This has several benefits:
batch()
; the number of bug reports in which the solution was "usebatch()
" and that wasn't obvious to the user is more than a handful.)The canonical example of why this is good would be something like
However, there are some situations in which users want an effect that runs immediately when signals are changed, and that does not batch in this way.
Describe the solution you'd like
An alternative effect type whose
ReactiveGraph
andSubscriber
implementations are designed such that, when marked check or dirty, it simply runs its inner function, instead of triggering a notification to wake up an async task.This means
Effect
and render effects (created for closures passed into the view, for example) run in the async, batched way, but users can opt into immediate effects for other cases.Describe alternatives you've considered
flush_sync()
that allows you to tell all effects to run now, not on the next microtask. (Difficult to implement because the async runtimes we piggyback on don't expose what we need to do this.)The text was updated successfully, but these errors were encountered: