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 59 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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ size-plugin.json
stats-hydration.json
stats.json
stats.html
.vscode/settings.json

*.log
*.tsbuildinfo
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
Comment on lines +1 to +4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to remove this, but it helps me as a contributor - I have a bunch of settings in trpc https://github.com/trpc/trpc/tree/next/.vscode

3 changes: 3 additions & 0 deletions examples/react/transition/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["plugin:react/jsx-runtime", "plugin:react-hooks/recommended"]
}
27 changes: 27 additions & 0 deletions examples/react/transition/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

pnpm-lock.yaml
yarn.lock
package-lock.json

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
6 changes: 6 additions & 0 deletions examples/react/transition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `pnpm install`
- `pnpm dev`
16 changes: 16 additions & 0 deletions examples/react/transition/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" type="image/svg+xml" href="/emblem-light.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />

<title>TanStack Query React Suspense Example App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions examples/react/transition/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@tanstack/query-example-react-transition",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.62.8",
"@tanstack/react-query-devtools": "^5.62.8",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.3.3",
"typescript": "5.7.2",
"vite": "^5.3.5"
}
}
13 changes: 13 additions & 0 deletions examples/react/transition/public/emblem-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions examples/react/transition/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
QueryClient,
QueryClientProvider,
useQuery,
} from '@tanstack/react-query'
import { Suspense, use, useState, useTransition } from 'react'
import ReactDOM from 'react-dom/client'

const Example1 = ({ value }: { value: number }) => {
const { isFetching, promise } = useQuery({
queryKey: ['1' + value],
queryFn: async () => {
await new Promise((resolve) => setTimeout(resolve, 1000))
return '1' + value
},
})
const data = use(promise)

return (
<div>
{data} {isFetching ? 'fetching' : null}
</div>
)
}

const Example2 = ({ value }: { value: number }) => {
const { promise, isFetching } = useQuery({
queryKey: ['2' + value],
queryFn: async () => {
await new Promise((resolve) => setTimeout(resolve, 2000))
return '2' + value
},
// placeholderData: keepPreviousData,
})

const data = use(promise)

return (
<div>
{data} {isFetching ? 'fetching' : null}
</div>
)
}

const SuspenseBoundary = () => {
const [state, setState] = useState(-1)
const [isPending, startTransition] = useTransition()

return (
<div>
<h1>Change state with transition</h1>
<div>
<button
onClick={() =>
startTransition(() => {
setState((s) => s - 1)
})
}
>
Decrease
</button>
</div>
<h2>State:</h2>
<ul>
<li>last state value: {state}</li>
<li>
transition state: {isPending ? <strong>pending</strong> : 'idle'}
</li>
</ul>
<h2>2. 1 Suspense + startTransition</h2>
<Suspense fallback="fallback 1">
<Example1 value={state}></Example1>
</Suspense>
<h2>2.2 Suspense + startTransition</h2>
<Suspense fallback="fallback 2">
<Example2 value={state}></Example2>
</Suspense>
</div>
)
}

const queryClient = new QueryClient({
defaultOptions: {
queries: {
experimental_prefetchInRender: true,
staleTime: 10 * 1000,
},
},
})

const App = () => {
return (
<div>
<QueryClientProvider client={queryClient}>
<SuspenseBoundary />
</QueryClientProvider>
</div>
)
}

const rootElement = document.getElementById('root') as HTMLElement
ReactDOM.createRoot(rootElement).render(<App />)
24 changes: 24 additions & 0 deletions examples/react/transition/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "eslint.config.js"]
}
6 changes: 6 additions & 0 deletions examples/react/transition/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
plugins: [react()],
})
4 changes: 2 additions & 2 deletions packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,11 @@
includedProps.add('error')
}

return Object.keys(this.#currentResult).some((key) => {
return [...includedProps].some((key) => {

Check warning on line 701 in packages/query-core/src/queryObserver.ts

View check run for this annotation

Codecov / codecov/patch

packages/query-core/src/queryObserver.ts#L701

Added line #L701 was not covered by tests
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)
return changed

Check warning on line 705 in packages/query-core/src/queryObserver.ts

View check run for this annotation

Codecov / codecov/patch

packages/query-core/src/queryObserver.ts#L705

Added line #L705 was not covered by tests
})
}

Expand Down
Loading
Loading