-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Propagate the abort signal to allow for automatic query cancellation #9612
Conversation
When running the ecommerce demo and navigating quickly between pages, we now have errors about aborted operations in the console.
Those occur in the I wonder whether we should detect those errors and avoid the log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I can't reproduce the query cancellation in the tutorial example on my machine :(
Back to WIP: @fzaninotto and I discovered a bug where the users are not loaded correctly in the tutorial project. Error: |
Only thing left to do is to decide what to do with this |
Fixed! Back to RFR |
TanStack Query provides each query function with an AbortSignal instance. When a query becomes out-of-date or inactive, this signal will become aborted.
This PR takes advantage of this, by propagating the abort signal to the dataProvider and authProvider, to allow for automatically aborting the request when the query is canceled.
Todo
signal
to the parameters of all dataProvider and authProvider methodsHow to test
You can see query cancellation in action in
ra-data-json-server
ra-data-graphql
(<- you will need to comment out thefetchMock
part inexamples/demo/src/fakeServer/graphql.ts
and run a 'real' graphql server, e.g. withjson-graphql-server
)You can use the browser's DevTools to
With that in place, you can for instance click multiple times on the header of a Datagrid to toggle sorting in ASC or DESC order, and see in the Network tab that all requests except the last one are canceled.
How to update your DataProvider to benefit from this feature
DataProvider query functions (
getOne
,getList
,getMany
andgetManyReference
) are now provided with an additionalsignal
parameter. This parameter is an AbortSignal that can be used to abort the request when the query is canceled (e.g. when it becomes out-of-date or inactive).The following dataProviders, provided by react-admin, have already been updated to support this new parameter:
ra-data-json-server
ra-data-simple-rest
ra-data-graphql
This feature is optional, so you can still use any other dataProvider, even if it doesn't yet support the
signal
parameter.If you wish to update your own dataProvider to support this new parameter, you can take inspiration from how we updated the
ra-data-simple-rest
dataProvider:You can find more example implementations in the Query Cancellation guide.