Skip to content
Source
Sign inSign up
TanStack/query

createAsyncStoragePersistor's persistClient not respect throttleTime and not persisted final state queryClient #3331

Send to my agent
Closedhuanguolin(GitHub profile, opens in a new tab) opened this issue 6 comments

Describe the bug

The persistClient of createAsyncStoragePersistor does not execute according to the throttleTime and not persisted final state queryClient when make many queries to refetch. To be precise, there is a problem with the function asyncThrottle.

Your minimal, reproducible example

https://www.typescriptlang.org/play?#code/FAYw9gdgzgLgBDAprAjHAvHAhlAnhEAFQAsAnMGGAG0QAod8Q5aBLAEwC44IBXAWwBGiUgEoMAPjgBvYHDjhoYGgDoqYAOa0ABiByI4aVpzgASKewC+I5QhZ9kMLHwAOXMwBEsSZRDAB3WhELLREAbllsPywWeDZEKixcWgBmAAYw4AsAGmkIlggkUgA3LCouFFTKrMyM0EhYBAcAJgxsPAISckoaenamIy5eQWExdEkZOQUoJURVDW1dKH0WgdNzNisbGDsHJ1c1z29fAKCQ8LksKJi4OISkpsr00LgAehf5MAbt+zgBFnV1MIEMQsBA4PlCiUqJkchNwQVhFDyo9qlZwsA3nAAMJUFggADWcAA5AAlHgQIm-HiUSAIMDyYiIAlwMDU5zUuBqdRQDjADHvRb6FC8zEAUQAHs4mfAuQg-PTcRBkFT4OoKHAAGas0jYCBsTk4eDscFQeHgUikaXKYC9RjMUbjCJIVC0FAZOTOmAoWhNd2RaKxeKJFIAVj9nu9yT9lwDNyDSWSYfOjRdABYMlZAujMYK4E0Re8JVKQDKNHKFfllQIOWr4JB9KD9QkGsaWKb8ubLSXrbaCPaJLkPc1XeHh77wpnagw+xrySWWLTbsG+DzuPwhKJB3J-dclX44AAFch8Nt0WiW6ZUIqIB1b7fbpYwQg7Vkwc-IJTXnIrv1yNGZPl+TgYhKGcHk3nUGJiB4ARlHAPgXkcCAlVIRUoBoXAXktLASwAWgARx4YRMIENQBBeLAsAADhDZI2CopoADY2EYgB2VjGMQVJWOSAQAE4NRDNgBDYNhkioxAQw1DUsCaVisBDJoBHIqBSBAF4QGwpAAEE+gAZRgMBSCwQED2EKA20KF58jicVlBgKAAGIABkQ1TYBZwIbZaWnIgyAoahEAAHm00huTgRBxSQPVTWwthICoXA4HJfFjggABtABdHISWQHgqBgcRaAiTyQC4WhlEqrAwtXULuVvI8wBPJYgtyqB8sK6o5CkeFIVKVoKiqTk7GuTA0AsLgeohRFSgAfkGddhGeXETxgea12GHULFaKQLGAMQ4RYDVmBgXApTAY7SrgABCdBMCJUrvIpMQYH8-c9zgUULSM2giWq9R+EQAoTW4dVHoXCBlCJEQIimeBSHJCB8nUHb5B4C0gZgLgZKoJY4D2uQaBlQ1nx+TBUgiInbHsV8uFymB0YgQgzuC07zuOx9ScQV9xFh+p4EIxAiK4ULjNwEKaskTAsoiS0GdIMEKqqmqRZqh0IjkXt+lvOF7yO5gEeQ5G4PRy0CgOjX7wNWAudaQ5ZmOQJLb147aEFojVCB9RXrgSQVpiC2rat93ZigYgjrfGGg7-Plo7gEPlHZMP6DV53txAGhqq519aG+bnqSjq2Cat-XaHtnx-ECOBcOtp8dl93qZqoQPo8NpGIHUE2MeBzAYARxA04uK54FKpXlH+qBC6D5s67JuBy8dqerbb42QFNzHWhxpY0+2+I8d1kvXYTmgO59yR0jvaO4drurTUwEP0uPr2fZrlBMuuwftzz19Wk5l9qS1v2MYl846l2uivDuXczYwBbnHe8EDO5r27vAXu-dP5BxjNcUelVVCGlvkvOBcAEFQI3pgLeA9CEx0IdkRuxRSgEO3MXe8TD8YiCdhYIAA

Steps to reproduce

Just run the code on the TypeScript playground.

  1. Click 'Run' button on the left panel.
  2. Click 'Logs' button on the right panel.
  3. Check output logs.

Expected behavior

Case1: Expect log two lines and print maximum id but got four lines and not print maximum id. Case2: Expect log two lines and print maximum id but got one line and not print maximum id.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

Only react native.

react-query version

v4.0.0-alpha.14 and v3.34.16

TypeScript version

No response

Additional context

No response

  1. Thanks for reporting. If you know how to fix it, I think the best thing would be to:

    • create some tests for this function
    • fix it :)
    • contribute to the alpha branch

    would you like to do that?

    I quickly tried out the first async-throttle package I could find on npm and made a codesandbox with your tests:

    • case 1 logs 2 times, which seems correct
    • case 2 logs 1 time, which you claim is not correct. However, your test case is not awaiting the first invocation, so both fire off at the same time, getting deduped, which seems fine?

    btw, I'm not suggesting to add a dependency, just saying we can use this or other implementations as reference.

  2. @TkDodo Thank you for your prompt response! Regarding your test, simply speaking the results of the third party library are right and the best. Case 2 expects to print once or twice is acceptable, but the last time must output that maximum id, otherwise the final state may not be persisted.

    would you like to do that?

    Yes! I will fix this problem later.

  3. @huanguolin to do that, I moved the log statements to after the delay:

    case 1 (id: 2). timestamp: 1645607386557 
    case 1 (id: 4). timestamp: 1645607387561 
    case 2 (id: 2). timestamp: 1645607388528 

    looking at the ids and the timestamps, this seems legit. Thank you for tackling this 🙇

  4. TkDodo added labelsbug

  5. @TkDodo I updated the bug description and then submitted the pr.

  6. TkDodo added labelsv4

  7. TkDodo closed this

  8. :tada: This issue has been resolved in version 4.0.0-alpha.19 :tada:

    The release is available on:

    Your semantic-release bot :package::rocket:

  9. tannerlinsley added labelsreleased on @alpha

  10. :tada: This issue has been resolved in version 4.0.0-beta.1 :tada:

    The release is available on:

    Your semantic-release bot :package::rocket:

  11. tannerlinsley added labelsreleased on @beta

Sign in to join this conversation.