You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I thought $effect.root could be used as a "safe environment" for housing effects when you do the care with cleaning up.
However, if that happens to be in onDestroy, then any effect will throw a runtime error regardless it's wrapped in an effect root or not.
To illustrate the use case let's say I have the following function:
exportasyncfunctionget_when_ready(getter,// getter to a reactive valuepredicate,){const{ promise, resolve }=Promise.withResolvers();constcleanup=$effect.root(()=>{$effect.pre(()=>{constvalue=getter();if(predicate(value)){resolve(value);}});});// clean the $effect.root after the promise has resolved/rejectedpromise.catch(()=>{}).finally(cleanup);returnpromise;}
Firstly, I don't know if the function is implemented correctly, if not, I'll be glad for any hints. I haven't seen it implemented elsewhere, but also I haven't looked thoroughly.
Given the above utility function and an API that calls it internally, I ran into a situation, where I called the API in the onDestroy of a component.
Note that it doesn't make much sense for the API (MyContext.delete_feature) to call the utility function there, but I hope it's sufficient to illustrate the problem.
I wonder if it's a false positive error or there's some underlying issue there.
Ok, so in my understanding, there's currently no way to correctly implement the get_when_ready function using effects that would work even in the destroying context, right?
Would adding a new rune $effect.destroying be an option? I understand that probably the use case is too niche though..
EDIT: I just realized that I could just do with try-catching the effect since this awaiting stuff is probably only temporary and the API should be refactored not to use it.
Describe the bug
I thought
$effect.root
could be used as a "safe environment" for housing effects when you do the care with cleaning up.However, if that happens to be in
onDestroy
, then any effect will throw a runtime error regardless it's wrapped in an effect root or not.To illustrate the use case let's say I have the following function:
Firstly, I don't know if the function is implemented correctly, if not, I'll be glad for any hints. I haven't seen it implemented elsewhere, but also I haven't looked thoroughly.
Given the above utility function and an API that calls it internally, I ran into a situation, where I called the API in the
onDestroy
of a component.Reproduction
The REPL is here: https://svelte.dev/playground/d96d1b9b36264a6a83685b0e99552969?version=5.19.9
Note that it doesn't make much sense for the API (
MyContext.delete_feature
) to call the utility function there, but I hope it's sufficient to illustrate the problem.I wonder if it's a false positive error or there's some underlying issue there.
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: