How does Transition API and createAsync interact?
https://github.com/sabercoy/solid-transition
this is a new solid start project with code only added to Home route
I don't understand why calling an async funtion inside createAsync causes the signal to be reverted back to as it was before the transition. I expected that setting a signal, even inside a transition start, would keep the new signal consistent with its new value.
In the snapshot, I wish to know why "after async function" is 0 and not 30 like the rest of them.
GitHub
GitHub - sabercoy/solid-transition
Contribute to sabercoy/solid-transition development by creating an account on GitHub.
5 Replies
Until the transition is committed anything outside it's execution will read the old value. The problem here is we can't restore the Transition after the await. Not until we get the returned result. There is no mechanism in JavaScript that let's us intercept there. Usually this isn't a problem as createAsync like createMemo is meant to be pure.. ie no writing other state inside it.
Of course we can't enforce that for the same reason.
anything outside it's execution will read the old value. The problem here is we can't restore the Transition after the awaitahhhh i understand now
Yeah what is interesting about async functions is from the outside whether there is 1 await or 10 you only see one promise. It makes sense but everything after the first await basically becomes squashed from the outside.
hmm.. Im curious then what actually kicks off the transition, is it the invoking of the transition start function, or is it the awaiting of an async function
seems from the logs the transition didnt start until it hit the await
from there it seems, from what you said, that we enter into a separate execution context and lose contact with the old one
I understand what transitions do on a high level, like hold on to the old state and view while the new one is being processed, then swap
but as far as how it works under the hood in terms of the JS language/runtime I dunno XD
startTransition is what starts it. We start collection all the changes downstream of anything set during that scope, forking it from the main (visible graph). As it propagates if we hit any async resources we associate them with the Transition and finally when all of those async things done we can commit all the changes back to the main graph.