Skip to content

Commit

Permalink
ci: apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Dec 13, 2024
1 parent 87ea4ec commit e8e5488
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ export class QueryObserver<
}

updateResult(notifyOptions?: NotifyOptions): void {

const prevResult = this.#currentResult as
| QueryObserverResult<TData, TError>
| undefined
Expand Down Expand Up @@ -712,7 +711,7 @@ export class QueryObserver<
includedProps,
})

return changed;
return changed
})
}

Expand Down
10 changes: 3 additions & 7 deletions packages/react-query/src/__tests__/useQuery.promise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
import { QueryCache } from '../index'
import { createDeferred, createQueryClient, queryKey, sleep } from './utils'



describe('useQuery().promise', () => {
const queryCache = new QueryCache()
const queryClient = createQueryClient({
Expand Down Expand Up @@ -77,7 +75,7 @@ describe('useQuery().promise', () => {
withinDOM().getByText('loading..')
expect(renderedComponents).toEqual([Page, Loading])
}

{
const { renderedComponents, withinDOM } = await renderStream.takeRender()
withinDOM().getByText('test')
Expand Down Expand Up @@ -1041,7 +1039,6 @@ describe('useQuery().promise', () => {
const key = queryKey()
const renderStream = createRenderStream({ snapshotDOM: true })


function MyComponent(props: { promise: Promise<string> }) {
useTrackRenders()
const data = React.use(props.promise)
Expand Down Expand Up @@ -1096,12 +1093,11 @@ describe('useQuery().promise', () => {

{
rendered.getByText('inc').click()

const { renderedComponents, withinDOM } = await renderStream.takeRender()
withinDOM().getByText('test0')
console.log({renderedComponents})
console.log({ renderedComponents })
expect(renderedComponents).toEqual([Page, MyComponent])

}

{
Expand Down
15 changes: 7 additions & 8 deletions packages/react-query/src/__tests__/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ export function setIsServer(isServer: boolean) {

export const doNotExecute = (_func: () => void) => true


export function createDeferred<TValue>() {
let resolve: (value: TValue) => void;
let reject: (error: unknown) => void;
let resolve: (value: TValue) => void
let reject: (error: unknown) => void
const promise = new Promise<TValue>((res, rej) => {
resolve = res;
reject = rej;
});
resolve = res
reject = rej
})

return { promise, resolve: resolve!, reject: reject! };
return { promise, resolve: resolve!, reject: reject! }
}
export type Deferred<TValue> = ReturnType<typeof createDeferred<TValue>>;
export type Deferred<TValue> = ReturnType<typeof createDeferred<TValue>>
11 changes: 4 additions & 7 deletions packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,27 @@ export function useBaseQuery<
),
)

const [result, setResult] = React.useState(() => observer.getOptimisticResult(defaultedOptions))
const [result, setResult] = React.useState(() =>
observer.getOptimisticResult(defaultedOptions),
)

// console.log('result', result)
React.useEffect(() => {
if (isRestoring) {
return
}
console.log('subscribing to observer')


const unsubscribe = observer.subscribe(
notifyManager.batchCalls((newResult) => {

setResult((prev) => {
console.log('got new result', {
prev,
newResult,
})
return newResult


})
})
}),
)

// Update result to make sure we did not miss any query updates
Expand All @@ -114,7 +112,6 @@ export function useBaseQuery<
return unsubscribe
}, [observer, isRestoring])


React.useEffect(() => {
console.log('setting options', defaultedOptions)
// Do not notify on updates because of changes in the options because
Expand Down

0 comments on commit e8e5488

Please sign in to comment.