[] = []
+
+ function Page() {
+ const state = useQuery(key, () => 'test', {
+ notifyOnChangeProps: 'tracked',
+ notifyOnChangePropsExclusions: ['data'],
+ })
+
+ states.push(state)
+
+ return (
+
+
{state.data ?? 'null'}
+
+ )
+ }
+
+ const rendered = renderWithClient(queryClient, )
+
+ await waitFor(() => rendered.getByText('null'))
+ expect(states.length).toBe(1)
+ expect(states[0]).toMatchObject({ data: undefined })
+
+ await queryClient.refetchQueries(key)
+ await waitFor(() => rendered.getByText('null'))
+ expect(states.length).toBe(1)
+ expect(states[0]).toMatchObject({ data: undefined })
+ })
+
+ it('should return the referentially same object if nothing changes between fetches', async () => {
+ const key = queryKey()
+ let renderCount = 0
+ const states: UseQueryResult[] = []
+
+ function Page() {
+ const state = useQuery(key, () => 'test', {
+ notifyOnChangeProps: 'tracked',
+ })
+
+ states.push(state)
+
+ const { data } = state
+
+ React.useEffect(() => {
+ renderCount++
+ }, [state])
+
+ return (
+
+
{data ?? null}
+
+ )
+ }
+
+ const rendered = renderWithClient(queryClient, )
+
+ await waitFor(() => rendered.getByText('test'))
+ expect(renderCount).toBe(2)
+ expect(states.length).toBe(2)
+ expect(states[0]).toMatchObject({ data: undefined })
+ expect(states[1]).toMatchObject({ data: 'test' })
+
+ act(() => rendered.rerender())
+ await waitFor(() => rendered.getByText('test'))
+ expect(renderCount).toBe(2)
+ expect(states.length).toBe(3)
+ expect(states[0]).toMatchObject({ data: undefined })
+ expect(states[1]).toMatchObject({ data: 'test' })
+ expect(states[2]).toMatchObject({ data: 'test' })
+ })
+
+ it('should always re-render if we are tracking props but not using any', async () => {
+ const key = queryKey()
+ let renderCount = 0
+ const states: UseQueryResult[] = []
+
+ function Page() {
+ const state = useQuery(key, () => 'test', {
+ notifyOnChangeProps: 'tracked',
+ })
+
+ states.push(state)
+
+ React.useEffect(() => {
+ renderCount++
+ }, [state])
+
+ return (
+
+
hello
+
+ )
+ }
+
+ renderWithClient(queryClient, )
+
+ await waitFor(() => renderCount > 1)
+ expect(renderCount).toBe(2)
+ expect(states.length).toBe(2)
+ expect(states[0]).toMatchObject({ data: undefined })
+ expect(states[1]).toMatchObject({ data: 'test' })
+ })
+
it('should be able to remove a query', async () => {
const key = queryKey()
const states: UseQueryResult[] = []
diff --git a/src/react/useBaseQuery.ts b/src/react/useBaseQuery.ts
index 05c7becdde..c75338b5a8 100644
--- a/src/react/useBaseQuery.ts
+++ b/src/react/useBaseQuery.ts
@@ -79,5 +79,7 @@ export function useBaseQuery(
}
}
- return currentResult
+ return observer.options.notifyOnChangeProps === 'tracked'
+ ? observer.getTrackedCurrentResult()
+ : currentResult
}