cube-js / cube-js/cube

[cubejs-client-react] `useCubeQuery` `isLoading` is always true for empty query

Open
#9,985 3 comments 1 reaction 0 assignees View on GitHub
client:react help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
`isLoading` for `useCubeQuery` is forever `true` if the query is empty.

**To Reproduce**

1. Use `useCubeQuery` to send a query that is empty (empty lists for dimensions, measures, etc)
2. Notice `isLoading` is always set to true

In the [sandbox](https://codesandbox.io/p/devbox/cube-js-react-client-forked-ckn4pw?from-embed=&workspaceId=ws_9LwRNrCprMsntvKXYoKcfh), notice how it's forever "Loading...". And the console logs `isLoading` as true too, even though the request finished long ago.

In the code:

[The default value for `isLoading` on L12](https://github.com/cube-js/cube/blob/v1.2.34/packages/cubejs-client-react/src/hooks/cube-query.js#L12) is the same as the opposite of the `skip` option. Then [the `isQueryPresent` check for empty query](https://github.com/cube-js/cube/blob/v1.2.34/packages/cubejs-client-react/src/hooks/cube-query.js#L72) skips everything else so `isLoading` is never updated again.

**Expected behavior**
`isLoading` should be false as soon as the request finishes/never been fired, whether the query was empty or not.

**Minimally reproducible Cube Schema**

N/A

**Version:**
Noticed on the latest 1.2, but seems like it's been there since 1.1

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.