Comments (10)
Hey @Arno500 π
I've got a fix for this issue in #11706 and have confirmed this addresses the problem. See my fork of the reproduction which uses a snapshot build from that PR for a working example.
from apollo-client.
Hey @Arno500 π
I'll dig into this a bit more deeply, but as an FYI, something that stands out immediately is that React doesn't support async functions inside startTransition
. From the React docs:
The function you pass to
startTransition
must be synchronous. React immediately executes this function, marking all state updates that happen while it executes as transitions. If you try to perform more state updates later (for example, in a timeout), they wonβt be marked as transitions.
Its possible something is happening here that gets React in a weird state. Transitions essentially render your component in 2 different states at the "same time", one with the new value, and one with the old value. Its possible the async function might be doing something weird here and confusing React.
I'll play around with your demo a bit to understand if this is the root issue, but just wanted you to know that React doesn't support async functions for startTransition
π
from apollo-client.
Thank you very much for that thorough explanation. Then how would you recommend reacting on only the new values?
I mean, in this case, I want to check that the incoming value (and not the total data) is empty. So how would it pan out with Apollo?
from apollo-client.
It would mostly be a matter of moving some code around.
Here is a version that uses a synchronous callback, but allows you to wait for the data to finish:
const fetchMoreData = async () => {
console.log('Probably have more data: ', hasMore);
if (!hasMore) return;
let promise!: Promise<ApolloQueryResult<any>>;
startTransition(() => {
promise = fetchMore({
variables: {
limit: 5,
offset: data.histories.length,
},
});
});
const { data: newData } = await promise;
console.log('Just received data: ', newData);
if (newData.histories.length < 1) {
console.log('Out of data, we consumed everything');
setHasMore(false);
}
};
I threw this into my own fork of the reproduction, but looks like it doesn't really change much. So it seems like its likely an Apollo Client bug!
from apollo-client.
I can reproduce this issue in my code as well.
I used this workaround of using readyQuery to solve temporarily this issue :
#11315 (comment)
from apollo-client.
@DenisLaboureyras can you please verify that you are still experiencing this in 3.9.6?
from apollo-client.
@phryneas yes unfortunately i'm still experiencing this in 3.9.6.
As stated by @Arno500, the last fetchMore with an empty incoming array is reseting the cache
from apollo-client.
Some discovery notes:
I think I've narrowed this down to something in QueryReference
itself. We are emmitting the wrong result on the promise
. The cache seems fine and contains the full data set, we just are giving the wrong value from the hook.
from apollo-client.
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.
from apollo-client.
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.
For general questions, we recommend using StackOverflow or our discord server.
from apollo-client.
Related Issues (20)
- BatchHTTPLink is not monitoring friendly HOT 6
- Support extensions in useSubscription HOT 1
- React functionality 'useContext' is not available in this environment [Nextjs app] HOT 4
- Subscription doesn't deduplicate HOT 3
- Types `cache.modify` and `writeFragment` lead to TypeScript errors for documented Apollo examples when specifying generic parameter HOT 1
- SOLVED : TypeError: Cannot return null for non-nullable field Subscription: Next.js frontend + FastApi backend HOT 2
- NextJS with "useSuspenseQuery" not passing headers to request HOT 3
- Using @defer in a query on a field which was previously queried creates a cache hit, when it should be a miss HOT 1
- Custom ApolloLink using `next.subscribe` is making duplicated requests HOT 8
- Adding graphql-tag-swc-plugin to performance docs for apollo client HOT 4
- (Batch)HttpLink Uncaught (in promise)DOMException: signal is aborted without reason HOT 6
- Typeguard for useQuery fails when the queryOptions passed using spread operator HOT 4
- Can you use `useFragment` with a type that doesn't have an id? HOT 3
- refetch does not return cached data HOT 5
- PossibleTypes not working as intended HOT 4
- Infinite network requests with non-normalized objects HOT 3
- fetchMore not hitting onError and causing an infinite loop of queries HOT 3
- [Docs] refetchQueries can fetch non active queries HOT 2
- Typescript compilation error in Node context HOT 1
- I try to integrate GraphQL PHP in backend with Apollo client and React in front end) but I get an undefined post response HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-client.