Replies: 1 comment 1 reply
-
you can either use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a situation where I need all the data from
useSuspenseQueries
to be updated atomically when the cache is invalidated. The basic idea that elements of a collection can move from one API endpoint to another, but I merge the two endpoints for display. The behavior ofinvalidateQueries
is that the cache entries are marked stale, anduseSuspenseQueries
will return the stale data until it is refreshed. This means that since the queries finish at different times, sometimes collection elements are duplicated between the two queries, or sometimes they are dropped. See the below repro:Clicking the
Do the thing
button a few times will show the list sometimes has 2 or 4 items instead of the expected 3. (Additionally, React will probably complain about a duplicated ID used as a key).Note I am aware that to some extent, what I'm asking for is unsound, because querying two API endpoints is not really atomic, so even on the first request, the two endpoints may be out of sync with each other. In practice, I'm willing to ignore the situation where the client requests endpoint A, the data changes, and then the client requests endpoint B.
1st question: Is there anything out of the box to support this behavior?
2nd question: If not, I have created a
useAtomicSuspenseQueries
that works (at least for my use case). Are there any obvious issues with it? See the code below,useAtomicSuspenseQueries
is a drop-in replacement foruseSuspenseQueries
in theTest
component.Beta Was this translation helpful? Give feedback.
All reactions