Replies: 1 comment 5 replies
-
once we start supporting dates, we will also have to support |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Our API layer is replacing string dates with Date instances already. However, now we loose the whole structural sharing capability of react-query, because: Structural sharing only works with JSON-compatible values. So as soon as we have a date in a resource, it is always considered changed, even if it is absolutely identical. This becomes particularly problematic in collections or nested structures. That is also the reason the function
isDataEqual
as proposed in discussion #3559 is not a solution we can use. I know this function, but it allows me only to declare a whole collection as equal or not. If there is just one entry with a different date, the function must returnfalse
. But then the defaultreplaceEqualDeep
function is used, where I do not have any possibility to get involved, and so I get a collection with all entries changed.The problem is, that Javascript supports serialization of Date but can't provide the same for deserialization. But we do not want to have this inconsistency and suddenly being confronted with string values that actually should be dates. That's why our deserialization supports Date as well, and we do not want to loose this.
At the moment we have to do some patching of
replaceEqualDeep
with something like this at the very end of the function:if (a instanceof Date && b instanceof Date && a.valueOf() === b.valueOf()) { return a; }
This would not be necessary if either:
replaceEqualDeep
would support the Date type by default as wellreplaceEqualDeep
could be provided the same way as it is possible withisDataEqual
(if you don't want the date type in the default implementation)Even if I would move the date transformation above the react-query layer, that would not work unless i use a second cache layer. If I change the instances returned by react-query, the
replaceEqualDeep
would not work again the next time. So I have to create a second copy of the data. And that is also not a good solution in my opinion, because react-query does this very well already.query/src/core/utils.ts
Lines 346 to 373 in 9f6c992
Beta Was this translation helpful? Give feedback.
All reactions