TanStackT
TanStackโ€ข3y agoโ€ข
21 replies
exclusive-coral

setQueryData and structuralSharing

Hey! I have a question about structural sharing behavior when calling setQueryData manually.
I have a query which I want to be updated only manually by setQueryData, so I set staleTime and cacheTime to Infinity.
I also set structuralSharing to
false
, so my component always react to
data
changes after manual setQueryData call, even if updated data is exactly the same as previous one.

The thing is that it doesn't. If new data is new object (made by spread operator), but is deeply equal to old data,
data
property returned from this query still has the same reference and it doesn't trigger useEffect(..., [data]).
I also tried to use structuralSharing as the function, so I check if it's called properly. But it never gets called.
However, if I change any property inside my data when calling setQueryData,
data
from query has new reference and all works as expected.

I really would like to understand how setQueryData and structuralSharing works together under the hood. I have pretty big object under this query key and I would like to make sure then structural sharing is really disabled and replaceEqualDeep never gets called for this query.

And btw thanks for this incredible library ๐Ÿ™
Was this page helpful?