Git Product home page Git Product logo

Comments (5)

TkDodo avatar TkDodo commented on May 28, 2024 1

interesting. so I added another log that just imperatively reads queryClient.isFetching() right before calling fetchNextPage, and we can really see that it's already at 1 (which means there is a fetch going on) while the fetchNextPage variable is still at false:

 invoking fetchNextPage(), isFetching is 0
  fetchBranches()
 isFetchingNextPage: ❌
 invoking fetchNextPage(), isFetching is 1
  fetchBranches()
4 isFetchingNextPage: ✅
2 fetched 200 - 300

This could be because we batch updates to observers together to avoid frequent renders, but in this case, where every minimal scroll seems to trigger a re-render, this could interfer.

We allow overriding how we batch things in the latest v5 version with notifyManager.setScheduler

I tried setting it to not batch at all with:

notifyManager.setScheduler((cb) => cb());

and I haven't been able to reproduce the issue since.

You can also try requestAnimationFrame or queueMicrotask to see if that yields better results for you over our default settings.

from query.

TkDodo avatar TkDodo commented on May 28, 2024 1

Would it be possible to apply this setting to just one query

not possible, because it's about batching updates together, and that doesn't happen on a per-query level.

is it safe to use the requestAnimationFrame or queueMicrotask option for the entire project?

absolutely - any batching mechanism is okay. Some might result in more re-renders than others. We might switch default in a future major, but that's not decided.

from query.

TkDodo avatar TkDodo commented on May 28, 2024

I can't reproduce this in the sandbox and your video doesn't play for me ...

from query.

yarokon avatar yarokon commented on May 28, 2024

@TkDodo, try opening the video in a different browser. The example is reproducible, but it may require several attempts to see the issue.

from query.

yarokon avatar yarokon commented on May 28, 2024

Thanks, @TkDodo. Batching with setTimeout(callback, 0) as a default setting was the main reason why isFetchingNextPage wasn't updated in the next render cycle. cb = cb() works in 100% of cases 🎉, and requestAnimationFrame and queueMicrotask also work almost perfectly (I only saw one parallel request among 200 pages).

Would it be possible to apply this setting to just one query, not the entire project? If yes, how can it be done? If no, is it safe to use the requestAnimationFrame or queueMicrotask option for the entire project?

P.S. Also, it would be good to mention it here: TanStack Infinite Scroll

from query.

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.