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 36 commits into
base: main
Choose a base branch
from
Open

Conversation

KATT
Copy link
Contributor

@KATT KATT commented Dec 13, 2024

Closes #8384 (I think/hope !?!!?)

Refactor @tanstack/react-query to not rely on useSyncExternalStore() as it creates issues in concurrent rendering

Copy link

nx-cloud bot commented Dec 13, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d878172. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link

pkg-pr-new bot commented Dec 13, 2024

Open in Stackblitz

More templates

@tanstack/angular-query-devtools-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@8434

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@8434

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@8434

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@8434

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@8434

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@8434

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@8434

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@8434

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@8434

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@8434

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@8434

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@8434

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@8434

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@8434

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@8434

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@8434

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@8434

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@8434

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@8434

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@8434

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@8434

commit: d878172

autofix-ci bot and others added 3 commits December 13, 2024 12:58
@@ -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? 🤷

Comment on lines +19 to +22
const filtersRef = React.useRef(filters)
React.useEffect(() => {
filtersRef.current = filters
}, [filters])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

useMutationState() was memoizing filters, so I'm guessing we should be doing it here too

Comment on lines 85 to 86
const [result, setResult] = React.useState(() =>
observer.getOptimisticResult(defaultedOptions),

This comment was marked as outdated.

Comment on lines 710 to 713
console.log(`changed key "${typedKey}"?`, changed, {
prev: this.#currentResult[typedKey],
next: prevResult[typedKey],
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
console.log(`changed key "${typedKey}"?`, changed, {
prev: this.#currentResult[typedKey],
next: prevResult[typedKey],
})

@@ -698,11 +704,14 @@ export class QueryObserver<
includedProps.add('error')
}

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

Choose a reason for hiding this comment

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

Tiny optimization that also made debugging a bit easier

@@ -2485,38 +2486,6 @@ describe('useQuery', () => {
expect(queryCache.find({ queryKey: key })!.options.retryDelay).toBe(20)
})

it('should batch re-renders', async () => {
Copy link
Contributor Author

@KATT KATT Dec 13, 2024

Choose a reason for hiding this comment

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

This test doesn't work anymore when we're force rendering

I'm guessing we just have to trust the concurrency in React to do this in an optimal way?

@@ -82,26 +82,27 @@ export function useBaseQuery<
),
)

const [_, setForceUpdate] = React.useState(0)

const result = observer.getOptimisticResult(defaultedOptions)
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 wanted to use a useState() here but it made the blast radius really big and broke useSuspense()'s test etc

@KATT KATT marked this pull request as ready for review December 13, 2024 16:05
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.

Project coverage is 63.11%. Comparing base (465906a) to head (d878172).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #8434       +/-   ##
===========================================
+ Coverage   46.21%   63.11%   +16.89%     
===========================================
  Files         198      134       -64     
  Lines        7509     4809     -2700     
  Branches     1711     1340      -371     
===========================================
- Hits         3470     3035      -435     
+ Misses       3664     1535     -2129     
+ Partials      375      239      -136     
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@tanstack/angular-query-experimental 88.65% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 94.56% <0.00%> (ø)
@tanstack/query-devtools 4.78% <ø> (ø)
@tanstack/query-persist-client-core 57.73% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/react-query 96.29% <96.55%> (+0.74%) ⬆️
@tanstack/react-query-devtools 10.00% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 78.20% <ø> (ø)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query 87.33% <ø> (ø)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client 100.00% <ø> (ø)
@tanstack/vue-query 71.45% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

experimental_promise: A component was suspended by an uncached promise
1 participant