Giter Club home page Giter Club logo

Comments (10)

jerelmiller avatar jerelmiller commented on June 21, 2024 2

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.

jerelmiller avatar jerelmiller commented on June 21, 2024

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.

Arno500 avatar Arno500 commented on June 21, 2024

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.

jerelmiller avatar jerelmiller commented on June 21, 2024

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.

DenisLaboureyras avatar DenisLaboureyras commented on June 21, 2024

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.

phryneas avatar phryneas commented on June 21, 2024

@DenisLaboureyras can you please verify that you are still experiencing this in 3.9.6?

from apollo-client.

DenisLaboureyras avatar DenisLaboureyras commented on June 21, 2024

@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.

jerelmiller avatar jerelmiller commented on June 21, 2024

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.

github-actions avatar github-actions commented on June 21, 2024

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.

github-actions avatar github-actions commented on June 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.