cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.85k stars 1.77k forks source link

There should be a way to cancel the requests from useCubeQuery when the component has unmounted #8263

Open ashwanisinghh opened 5 months ago

ashwanisinghh commented 5 months ago

When we are using the useCubeQuery hook to get the data from cube server & user has routed to some other routes, while the result is being fetched. Then it should cancel out the request , as component from which the request was raised has already unmounted

To Reproduce Steps to reproduce the behavior:

  1. create a dashboard with multiple reports on it
  2. redirect to another route as soon as you have landed on dashboard
  3. In network tab of developer tool, you will see that the requests of reports on dashboard are still active, which is of no use now, as the dashboard component has already unmounted

Expected behavior Requests for reports data should have be cancelled out

shughes-uk commented 2 months ago

Plus one to this. Preferably also in the core library. We don't use the hook, but use the cube api client load function via react-query. Ideally we would be able to pass AbortSignal to the load function and have it respect it.

The query cancellation documentation react-query lays it out fairly well. I wouldn't consider it crazy specific specific to react-query, but helpful for things like cancelling fetch requests.

shughes-uk commented 2 months ago

I actually see some internal stuff referencing mutex that might be possible to use for this purpose, but there's no documentation for it as far as I can tell.

github-actions[bot] commented 2 months ago

If you are interested in working on this issue, please go ahead and provide PR for that. We'd be happy to review it and merge it. If this is the first time you are contributing a Pull Request to Cube, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube Slack.