Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/core/queryObserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
import { RefetchPageFilters } from './types'
import {
isServer,
isValidTimeout,
Expand Down Expand Up @@ -224,14 +224,7 @@ export class QueryObserver<
}

trackResult(
result: QueryObserverResult<TData, TError>,
defaultedOptions: DefaultedQueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>
result: QueryObserverResult<TData, TError>
): QueryObserverResult<TData, TError> {
const trackedResult = {} as QueryObserverResult<TData, TError>

Expand All @@ -246,10 +239,6 @@ export class QueryObserver<
})
})

if (defaultedOptions.useErrorBoundary) {
this.trackedProps.add('error')
}

return trackedResult
}

Expand Down Expand Up @@ -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]
Expand Down
24 changes: 24 additions & 0 deletions src/reactjs/tests/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | undefined

function Page() {
const query = useQuery(key, () => Promise.resolve('data'), {
useErrorBoundary: true,
})

React.useEffect(() => {
result = query
})

return null
}

renderWithClient(queryClient, <Page />)

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()
Expand Down
2 changes: 1 addition & 1 deletion src/reactjs/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down