Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-query): move away of uSES #8434

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7d3fccc
wip
KATT Dec 13, 2024
bc36411
wip
KATT Dec 13, 2024
63c548c
wip
KATT Dec 13, 2024
3ed5349
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
784cb83
wip
KATT Dec 13, 2024
fb21469
wip
KATT Dec 13, 2024
a7ba6bc
kinda works
KATT Dec 13, 2024
b6917d2
apparently this fixes stuff
KATT Dec 13, 2024
71ccdcf
ok works
KATT Dec 13, 2024
0faec03
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
16e9c59
bump
KATT Dec 13, 2024
510bcbe
wip
KATT Dec 13, 2024
76fd305
Merge branch 'issues/8384' of github.com:KATT/react-query into issues…
KATT Dec 13, 2024
f035539
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
ec4d91e
uhm
KATT Dec 13, 2024
bd25f47
Merge branch 'issues/8384' of github.com:KATT/react-query into issues…
KATT Dec 13, 2024
3002562
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
61d9be3
wip
KATT Dec 13, 2024
46d145c
wip
KATT Dec 13, 2024
201169a
reset
KATT Dec 13, 2024
3685c95
reset
KATT Dec 13, 2024
a1890ed
hi
KATT Dec 13, 2024
123d6e4
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
cc5d27f
wip
KATT Dec 13, 2024
f5c1e5d
Merge branch 'issues/8384' of github.com:KATT/react-query into issues…
KATT Dec 13, 2024
ab24be3
act fix
KATT Dec 13, 2024
27d348c
delete lib
KATT Dec 13, 2024
e2dca98
cleanup
KATT Dec 13, 2024
c0d3680
meep
KATT Dec 13, 2024
77f4616
less diff
KATT Dec 13, 2024
a1e2dd8
less diff
KATT Dec 13, 2024
50dfe93
cool
KATT Dec 13, 2024
3f6748a
mkay
KATT Dec 13, 2024
6e4a559
ci: apply automated fixes
autofix-ci[bot] Dec 13, 2024
2649b87
fucking lint
KATT Dec 13, 2024
d878172
revert
KATT Dec 13, 2024
4b9c5d8
test: startTransition
TkDodo Dec 16, 2024
19f7230
Merge branch 'feature/transition-tests' of github.com:TanStack/query …
KATT Dec 19, 2024
38b8864
fix test
KATT Dec 19, 2024
84dffdc
rm dep array
KATT Dec 19, 2024
a728d6b
mkay
KATT Dec 19, 2024
58f0f77
Merge branch 'main' into issues/8384
KATT Dec 19, 2024
984fa4b
failing test
KATT Dec 19, 2024
cfdf512
Merge branch 'issues/8384' of github.com:KATT/react-query into issues…
KATT Dec 19, 2024
ed313f7
mkay better test
KATT Dec 19, 2024
dcf16f2
might revert this later
KATT Dec 19, 2024
60f6736
prettier
KATT Dec 19, 2024
5a97880
Revert "might revert this later"
KATT Dec 19, 2024
aba6e7f
wait
KATT Dec 19, 2024
b5d30af
mkay
KATT Dec 19, 2024
e6a7d00
vscode helps
KATT Dec 20, 2024
847e7da
why doesn’t this failllll
KATT Dec 20, 2024
cb449e0
org
KATT Dec 20, 2024
4a5296c
add transition
KATT Dec 20, 2024
c0d341e
tweak
KATT Dec 20, 2024
02d9727
fix
KATT Dec 20, 2024
442c4d5
mkay
KATT Dec 20, 2024
f93377b
pendy
KATT Dec 20, 2024
76bfacf
revert useIsFetching etc etc
KATT Dec 20, 2024
efed3ff
does this fail?
KATT Dec 20, 2024
5a1358e
idk
KATT Dec 20, 2024
30e819b
wip
KATT Dec 20, 2024
83dddf0
fix test
KATT Dec 20, 2024
7e7d55c
ok
KATT Dec 20, 2024
7df5d81
test: add test case for 8249
TkDodo Jan 3, 2025
9096707
rest: re-order describe blocks to avoid "act not available in environ…
TkDodo Jan 3, 2025
9797e93
Merge branch 'main' into issues/8384
TkDodo Jan 3, 2025
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@eslint-react/eslint-plugin": "^1.17.1",
"@tanstack/config": "^0.14.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.5.2",
"@types/eslint": "^9.6.1",
"@types/node": "^22.9.3",
"@types/react": "npm:types-react@rc",
Expand Down
15 changes: 12 additions & 3 deletions packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class QueryObserver<
this.#executeFetch()
}

console.log('updating result due to setOptions()', notifyOptions)
// Update result
this.updateResult(notifyOptions)

Expand Down Expand Up @@ -609,6 +610,11 @@ export class QueryObserver<
* Create a new thenable and result promise when the results have changed
*/
const recreateThenable = () => {
console.log(
'-----------recreateThenable()',
'queryHash:',
query.queryHash,
)
KATT marked this conversation as resolved.
Show resolved Hide resolved
const pending =
(this.#currentThenable =
nextResult.promise =
Expand Down Expand Up @@ -698,11 +704,14 @@ export class QueryObserver<
includedProps.add('error')
}

return Object.keys(this.#currentResult).some((key) => {
return [...includedProps].some((key) => {
TkDodo marked this conversation as resolved.
Show resolved Hide resolved
const typedKey = key as keyof QueryObserverResult
const changed = this.#currentResult[typedKey] !== prevResult[typedKey]

return changed && includedProps.has(typedKey)
console.log(`changed key "${typedKey}"?`, changed, {
prev: this.#currentResult[typedKey],
next: prevResult[typedKey],
})
KATT marked this conversation as resolved.
Show resolved Hide resolved
return changed
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"devDependencies": {
"@tanstack/react-query": "workspace:*",
"@testing-library/react": "^16.0.1",
"@testing-library/react": "^16.1.0",
"@types/react": "npm:types-react@rc",
"@vitejs/plugin-react": "^4.3.3",
"react": "^19.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-persist-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"devDependencies": {
"@tanstack/react-query": "workspace:*",
"@testing-library/react": "^16.0.1",
"@testing-library/react": "^16.1.0",
"@types/react": "npm:types-react@rc",
"@vitejs/plugin-react": "^4.3.3",
"react": "^19.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"devDependencies": {
"@tanstack/query-persist-client-core": "workspace:*",
"@testing-library/react": "^16.0.1",
"@testing-library/react": "^16.1.0",
"@testing-library/react-render-stream": "^2.0.0",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
Expand Down
59 changes: 0 additions & 59 deletions packages/react-query/src/__tests__/useIsFetching.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,65 +54,6 @@ describe('useIsFetching', () => {
await findByText('isFetching: 0')
})

it('should not update state while rendering', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we should just trust React to optimize re-renders? 🤷

const queryCache = new QueryCache()
const queryClient = createQueryClient({ queryCache })

const key1 = queryKey()
const key2 = queryKey()

const isFetchingArray: Array<number> = []

function IsFetching() {
const isFetching = useIsFetching()
isFetchingArray.push(isFetching)
return null
}

function FirstQuery() {
useQuery({
queryKey: key1,
queryFn: async () => {
await sleep(100)
return 'data'
},
})
return null
}

function SecondQuery() {
useQuery({
queryKey: key2,
queryFn: async () => {
await sleep(100)
return 'data'
},
})
return null
}

function Page() {
const [renderSecond, setRenderSecond] = React.useState(false)

React.useEffect(() => {
setActTimeout(() => {
setRenderSecond(true)
}, 50)
}, [])

return (
<>
<IsFetching />
<FirstQuery />
{renderSecond && <SecondQuery />}
</>
)
}

renderWithClient(queryClient, <Page />)
await waitFor(() => expect(isFetchingArray).toEqual([0, 1, 1, 2, 1, 0]))
})

it('should be able to filter', async () => {
const queryClient = createQueryClient()
const key1 = queryKey()
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query/src/__tests__/useMutationState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('useIsMutating', () => {
}

renderWithClient(queryClient, <Page />)
await waitFor(() => expect(isMutatingArray).toEqual([0, 1, 0]))
await waitFor(() => expect(isMutatingArray).toEqual([0, 1, 1, 0, 0]))
})

it('should filter correctly by predicate', async () => {
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('useIsMutating', () => {
}

renderWithClient(queryClient, <Page />)
await waitFor(() => expect(isMutatingArray).toEqual([0, 1, 0]))
await waitFor(() => expect(isMutatingArray).toEqual([0, 1, 1, 0, 0]))
})

it('should use provided custom queryClient', async () => {
Expand Down
11 changes: 7 additions & 4 deletions packages/react-query/src/__tests__/useQuery.promise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import * as React from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import {
createRenderStream,
disableActEnvironment,
useTrackRenders,
} from '@testing-library/react-render-stream'
import { userEvent } from '@testing-library/user-event'
import {
QueryClientProvider,
QueryErrorResetBoundary,
Expand Down Expand Up @@ -79,7 +81,7 @@ describe('useQuery().promise', () => {
{
const { renderedComponents, withinDOM } = await renderStream.takeRender()
withinDOM().getByText('test')
expect(renderedComponents).toEqual([Page, MyComponent])
expect(renderedComponents).toEqual([MyComponent])
}
})

Expand Down Expand Up @@ -1035,7 +1037,7 @@ describe('useQuery().promise', () => {
expect(queryFn).toHaveBeenCalledTimes(0)
})

it('should show correct data when switching between cache entries without re-fetches', async () => {
it.only('should show correct data when switching between cache entries without re-fetches', async () => {
const key = queryKey()
const renderStream = createRenderStream({ snapshotDOM: true })

Expand Down Expand Up @@ -1091,10 +1093,11 @@ describe('useQuery().promise', () => {
expect(renderedComponents).toEqual([MyComponent])
}

rendered.getByText('inc').click()
await userEvent.click(rendered.getByText('inc'))

{
const { renderedComponents, withinDOM } = await renderStream.takeRender()
console.log('renderedComponents', renderedComponents)
withinDOM().getByText('loading..')
expect(renderedComponents).toEqual([Page, Loading])
}
Expand All @@ -1105,7 +1108,7 @@ describe('useQuery().promise', () => {
expect(renderedComponents).toEqual([MyComponent])
}

rendered.getByText('dec').click()
await userEvent.click(rendered.getByText('dec'))

{
const { renderedComponents, withinDOM } = await renderStream.takeRender()
Expand Down
Loading
Loading