Giter Club home page Giter Club logo

Comments (6)

phryneas avatar phryneas commented on September 23, 2024

That is kinda expected/intended behaviour.

useBackgroundQuery only creates a queryRef that a useReadQuery can attach to. Due to how suspense works, we have to keep around that reference, even if the component with useReadQuery would never be mounting.

If you don't attach to it in a useReadQuery within 30 seconds (see autoDisposeTimeoutMs), that subscription will be unsubscribed.

You'll see in your demo that once you add a useReadQuery to the whole thing, it behaves the way you'd expect.

We have to solve it this way (with the autoDisposeTimeoutMs) because we have to keep the subscription alive long enough for the useReadQuery component not only to suspend/try render, but until it is actually rendered and committed to the component tree. That's unfortunately a drawback of how Suspense works in React.

from apollo-client.

PiR1 avatar PiR1 commented on September 23, 2024

Thank you for your answer!

I hadn't seen this option (autoDisposeTimeoutMs) at all.

That's the problem I'm facing, my child component that reads the reference doesn't have time to mount.

But wouldn't it be a good idea, for performance reasons, to unsubscribe the subscription if the component that called the background query is unmounted and the reference hasn't been read?

from apollo-client.

jerelmiller avatar jerelmiller commented on September 23, 2024

@PiR1 I'm fairly confident this is related to #11438. An optimization we made in 3.9 with regards to background queries/query refs is what @phryneas described above, which is that if a queryRef is not read by useReadQuery in a given amount of time (autoDisposeTimeoutMs), the query ref is put in sort of an idle state.

The work in #11438 however did remove the detection of the background query unmounting. If I try this with 3.8.10 for example, I see the problem you're describing disappear.

Let me think through this a bit more. I stand by that change as I believe it is generally a positive one. But you have a good point about not keeping that subscription around when useBackgroundQuery unmounts before the autoDisposeTimeoutMs has kicked in. Let me play around with a couple things and see if we can get the best of both worlds.

from apollo-client.

jerelmiller avatar jerelmiller commented on September 23, 2024

I've got a failing test that demonstrates this issue: #11651. This also occurs when changing variables on useBackgroundQuery without consuming the queryRef before the autoDisposeTimeoutMs kicks in.

I tried a couple quick ideas without luck. I think this is going to require a bit more thought to try and nail all the cases down here and work well with strict mode. If you've got ideas and would like to contribute, feel free to use the tests in my PR as a base 🙂

from apollo-client.

PiR1 avatar PiR1 commented on September 23, 2024

Thank you for the update!
I'll try to have a look on my side too, thanks to the tests you've done.

from apollo-client.

github-actions avatar github-actions commented on September 23, 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.

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.