diff --git a/src/core/queryObserver.ts b/src/core/queryObserver.ts index 526bb07593..df0dd565bf 100644 --- a/src/core/queryObserver.ts +++ b/src/core/queryObserver.ts @@ -1,4 +1,4 @@ -import { DefaultedQueryObserverOptions, RefetchPageFilters } from './types' +import { RefetchPageFilters } from './types' import { isServer, isValidTimeout, @@ -224,14 +224,7 @@ export class QueryObserver< } trackResult( - result: QueryObserverResult, - defaultedOptions: DefaultedQueryObserverOptions< - TQueryFnData, - TError, - TData, - TQueryData, - TQueryKey - > + result: QueryObserverResult ): QueryObserverResult { const trackedResult = {} as QueryObserverResult @@ -246,10 +239,6 @@ export class QueryObserver< }) }) - if (defaultedOptions.useErrorBoundary) { - this.trackedProps.add('error') - } - return trackedResult } @@ -606,6 +595,10 @@ export class QueryObserver< const includedProps = new Set(notifyOnChangeProps ?? this.trackedProps) + if (this.options.useErrorBoundary) { + includedProps.add('error') + } + return Object.keys(result).some(key => { const typedKey = key as keyof QueryObserverResult const changed = result[typedKey] !== prevResult[typedKey] diff --git a/src/reactjs/tests/useQuery.test.tsx b/src/reactjs/tests/useQuery.test.tsx index b8b04fbc13..29cc7666f3 100644 --- a/src/reactjs/tests/useQuery.test.tsx +++ b/src/reactjs/tests/useQuery.test.tsx @@ -2672,6 +2672,30 @@ describe('useQuery', () => { consoleMock.mockRestore() }) + it('should update with data if we observe no properties and useErrorBoundary', async () => { + const key = queryKey() + + let result: UseQueryResult | undefined + + function Page() { + const query = useQuery(key, () => Promise.resolve('data'), { + useErrorBoundary: true, + }) + + React.useEffect(() => { + result = query + }) + + return null + } + + renderWithClient(queryClient, ) + + await sleep(10) + + expect(result?.data).toBe('data') + }) + it('should set status to error instead of throwing when error should not be thrown', async () => { const key = queryKey() const consoleMock = mockConsoleError() diff --git a/src/reactjs/useBaseQuery.ts b/src/reactjs/useBaseQuery.ts index a5f4d5f5dd..3a99bd1938 100644 --- a/src/reactjs/useBaseQuery.ts +++ b/src/reactjs/useBaseQuery.ts @@ -134,7 +134,7 @@ export function useBaseQuery< // Handle result property usage tracking if (!defaultedOptions.notifyOnChangeProps) { - result = observer.trackResult(result, defaultedOptions) + result = observer.trackResult(result) } return result