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 want to make it easier to write compute-intensive JavaScript functions which support yield()ing to main thread, and support AbortSignal signals to cancel any in-progress work. This is in support of writing Components which do not block main thread, allowing the UI to stay responsive (and do well on Interaction to Next Paint (INP)).
In particular, it would be very convenient to integrate with useTransition and <Suspense> where SolidJS already makes it very nice and easy to write async code.
Example usage:
const[isPending,startAwaitableTransition]=useAwaitableTransition();// an example of transitions that may happen in quick succession, like text input...constonInput=async(e)=>{try{// New: await transition end (until !pending)awaitstartAwaitableTransition(()=>{// Like today: Set up transition});// New: Clean up after transition}catch{// New: Clean up an abort transition}};
The fact that you can await a transition is not much different than just creating an Effect on transition pending... However, I am not aware of a way to (currently) run some clean-up code in situations where a transition is aborted by the start of another transition. This helper lets you just catch() a transition failure.
And, based on this, create a helper that automatically manages an AbortController which is signalled.
const[isPending,startAbortSignallingTransition,abortSignal]=useAbortSignallingTransition();constonInput=async(e)=>{try{awaitstartAbortSignallingTransition(()=>{// Set up transition});}catch{}// No desire to handle in this case};// ... can use abortSignal() in effects and rendering... will get automatically signalled whenever transition is aborted
Here was my stab at it... Some of the TypeScript types are likely to need improvement.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to make it easier to write compute-intensive JavaScript functions which support
yield()
ing to main thread, and supportAbortSignal
signals to cancel any in-progress work. This is in support of writing Components which do not block main thread, allowing the UI to stay responsive (and do well on Interaction to Next Paint (INP)).In particular, it would be very convenient to integrate with
useTransition
and<Suspense>
where SolidJS already makes it very nice and easy to write async code.Example usage:
The fact that you can await a transition is not much different than just creating an Effect on transition
pending
... However, I am not aware of a way to (currently) run some clean-up code in situations where a transition is aborted by the start of another transition. This helper lets you just catch() a transition failure.And, based on this, create a helper that automatically manages an
AbortController
which is signalled.Here was my stab at it... Some of the TypeScript types are likely to need improvement.
Beta Was this translation helpful? Give feedback.
All reactions