-
Notifications
You must be signed in to change notification settings - Fork 25
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
Cancellation #10
Comments
I think AbortSignal isn't fully supported in all browsers (safari) before promoting this pattern, are their polyfills // workarounds to resolve this? |
@joshuaellis sure there are polyfills though Safari supports it since Safari 11.1 (we are currently on Safari 15.2) so this should be safe. In any case there is a polyfill (the |
i think this would require another slight problem is the call signature because the parameters that suspend forwards are the cache keys ( so this would basically save bandwidth and avoid cpu/gpu overhead once the component unmounts? and the signal could be tested against right? so that if a browser doesn't have it, nothing happens and the thing that's loading will simply run its course wastefully. |
Right and also prevent cases where two
|
about the call signature, maybe: async function fn([a, b, c], { signal }) {
...
}
useSuspend(fn, [a, b, c]) so keys come out as they go in (as an array, no spread), second arg is an extensible object that could later be built out. |
That's pretty tricky, you would either need there to be a hook (even if suspend isn't) or you would need to wrap the component. Here are three options: function Post({ id, version }) {
suspend.useCancellation(); // suspend below is now cancellation aware
const data = suspend(async ({ signal }) => {
const res = await fetch(`https://hacker-news.firebaseio.com/${version}/item/${id}.json`, { signal })
return await res.json()
}, [id, version])
return (
<div>
{data.title} by {data.by}
</div>
)
}
function Post({ id, version }) {
const data = useSuspend(async ({ signal }) => { // suspend is a hook
const res = await fetch(`https://hacker-news.firebaseio.com/${version}/item/${id}.json`, { signal })
return await res.json()
}, [id, version])
return (
<div>
{data.title} by {data.by}
</div>
)
}
// the component is wrapped
const Post = suspended(function Post({ id, version }) {
const data = suspend(async ({ signal }) => {
const res = await fetch(`https://hacker-news.firebaseio.com/${version}/item/${id}.json`, { signal })
return await res.json()
}, [id, version])
return (
<div>
{data.title} by {data.by}
</div>
)
}) |
i would def prefer it to be a hook. i thought about it before and it used to be one. i just didn't use hooks until now and suspense can be randomly named, but thing like these would be an argument for doing it since it's more future proof. |
would you make a pr for this @benjamingr we can review and find solutions when it comes up |
I'm a bit scared to ask how to run the tests :D ? |
im glad you asked, because there aren't any. by all means ... add some :D |
I'm using useLoader from react-three-fiber and having issues with useEffect, after hours of debugging I figured out it is caused by a suspend inside useLoader... |
The ask here is:
AbortSignal
.e.g.
Basically allowing aborting expensive async actions.
The text was updated successfully, but these errors were encountered: