@cubejs-client/react 1.8.2 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,7 +70,7 @@ export function useCubeQuery(
70
70
  ): UseCubeQueryInternalResult {
71
71
  const mutexRef = useRef<MutexObj>({});
72
72
  const [currentQuery, setCurrentQuery] = useState<ReadonlyQueryInput | null>(null);
73
- const [isLoading, setLoading] = useState(!options.skip);
73
+ const [isLoading, setLoading] = useState(!options.skip && isQueryPresent(query));
74
74
  const [resultSet, setResultSet] = useState<ResultSet | null>(null);
75
75
  const [progress, setProgress] = useState<ProgressResponse | null>(null);
76
76
  const [error, setError] = useState<Error | null>(null);
@@ -239,10 +239,18 @@ export function useCubeQuery(
239
239
  context,
240
240
  ]));
241
241
 
242
+ // The effect above only catches up with a changed query after this render,
243
+ // so don't hand out the previous query's state in the meantime
244
+ const isQueryChanged = !options.skip
245
+ && isQueryPresent(query)
246
+ && !areQueriesEqual(currentQuery as DeeplyReadonly<Query> | null, query as DeeplyReadonly<Query>);
247
+ const shouldResetResultSet = isQueryChanged
248
+ && (options.resetResultSetOnChange == null || options.resetResultSetOnChange);
249
+
242
250
  return {
243
- isLoading,
244
- resultSet,
245
- error,
251
+ isLoading: isLoading || isQueryChanged,
252
+ resultSet: shouldResetResultSet ? null : resultSet,
253
+ error: isQueryChanged ? null : error,
246
254
  progress,
247
255
  previousQuery: currentQuery,
248
256
  refetch: fetch