Does query invalidation order metters? #8760
Unanswered
WingsDevelopment
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to understand if query invalidation order metters.
Lets say I have multiple child queries, that use queryclient.fetchQuery (so they will never be active, but they can have their own cache) and a single 'parent' (useQuery) query that calls multiple child queries. I want to build a developer friendly function to be able to invalidate single child and automatically invalidate all parents that uses that child.
for example: fetchLoopStrategy:


and the child would look something like this
hook with object (in array) as a key here,


invalidate it like this:
problem: if i swap the order of for each loops it doesn't work properly, every second time I see new value from equity. which means parent gets invalidated first, runs fetch function and gets old data from child before it is invalidated? but why new value every second invalidation instead of always 1 invalidation old value ?

so if i invalidate parent, parent trigger fetch method, gets old data, then i invalidate child, I basically get old value of a child ? But why do I see every second time i click the button new value, instead of delayed value by 1 click??
hook with array as a key

how i invalidate (the logic is if any element matches my query, please invalidate) so not like usual react query with order priority:

concerns:
is this killing my performance?
this works, am i just lucky?
can this guarantee that I will always get new value from child? and why does swapping foreach loops in first invalidation example metters, but here queries.map and queries.reverse().map works the same?
how i call invalidations:

Beta Was this translation helpful? Give feedback.
All reactions