-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Pagination using useSuspenseQuery and React transition is broken #11315
Comments
Thanks for reporting this, @pvandamme! Really appreciate the reproduction - looks like this issue should be transferred over to the Apollo Client repo which I will do shortly. |
Thanks @alessbell :) |
Hi @alessbell, any issue that I can follow on the apollo client repo for updates ? |
Faced a similar issue. |
Hi there, I'm sorry - it seems that something went wrong when transferring this earlier. I transferred it now. |
Is there any workaround available currently? |
@finkef |
@none23 Thanks! I just came up with this workaround, but wouldn't expect the best performance. It appears that import { useApolloClient } from "@apollo/client"
import { useSuspenseQuery as useApolloSuspenseQuery } from "@apollo/experimental-nextjs-app-support/ssr"
import { startTransition, useCallback, useMemo } from "react"
export const useSuspenseQuery: typeof useApolloSuspenseQuery = (
...args: Parameters<typeof useApolloSuspenseQuery>
) => {
const client = useApolloClient()
const { data, fetchMore, ...rest } = useApolloSuspenseQuery(...args)
const newFetchMore = useCallback(
(...fetchMoreArgs: Parameters<typeof fetchMore>) => {
return new Promise((resolve, reject) => {
startTransition(() => {
fetchMore(...fetchMoreArgs)
.then(resolve)
.catch(reject)
})
})
},
[fetchMore],
)
const actualData = useMemo(() => {
return client.readQuery({
query: args[0],
variables: (args as any)[1]?.variables,
})
}, [data])
return {
data: actualData,
fetchMore: newFetchMore,
...rest,
} as any
} |
Hey @pvandamme 👋 I finally got around to fixing this issue with #11638. I've tried this with your reproduction and this solves it. Would you mind trying this snapshot release to make sure it works on your end?
Note: You'll need a more modern version of the Next.js app support package since it uses some internals of Apollo Client from newer versions. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have a paginated query that I use with
useSuspenseQuery
.When I call the
fetchMore
function inside astartTransition
, an unexpected re-render with only the new data happens before the final re-render with all the data merged together.I've made a reproduction link so you can try it out : https://stackblitz.com/edit/stackblitz-starters-fqmtck?file=src%2Fcomponents%2FPaginatedQuery.tsx
Reproduction steps
1 - Go to the stackblitz link
2 - Open your console
3 - Click "Fetch More"
4 - Look at logs
The text was updated successfully, but these errors were encountered: