-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 🐛 Make sure queries which have dataUpdatedAt of 0 will be run #1556
Conversation
When initialDataUpdatedAt is a falsy numeric value (e.g. 0), it will cause it to be replaced with Date.now(). This leads to unexpected behaviour, as one would expect the query to be invalidated instantly, if staleTime is set to an amount less than the result of Date.now(). This change will check if the value is numeric, and if so, always use this numeric value. This changes the behaviour of the plugin for those users that have specified initialDataUpdated at <= 0.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/el66wgeg4 |
The problem is that a valid timestamp, 0 (number, 1970) is falsy, and
therefore gets converted to date now, the current timestamp (2020).
I'll find another way that doesn't involve involve making string values invalid
Op za 2 jan. 2021 18:33 schreef Dominik Dorfmeister <
notifications@github.com>:
… ***@***.**** commented on this pull request.
------------------------------
In src/core/query.ts
<#1556 (comment)>
:
> @@ -475,7 +475,11 @@ export class Query<
return {
data,
dataUpdateCount: 0,
- dataUpdatedAt: hasData ? initialDataUpdatedAt || Date.now() : 0,
that's true, but what else should it be? The types clearly state that it
should be number | undefined, and the docs say that it has to be *a JS
timestamp in milliseconds*.
I don't think that we need to check every option for every possible input
- that's what TypeScript is for. Yes, there are also (lots of) JS
consumers, but if I put in a string ("1608412420052") - would it not be
weird if that were converted to Date.now() ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1556 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIOEZFJORWV5BUG4OH3NT5TSX5KEXANCNFSM4VRFT4GQ>
.
|
Yes, I think I got the problem, and using |
Ah sorry, I misunderstood nullish coalescing, and therefore your comment. I see now, it makes a lot of sense. I will change the PR accordingly. |
Alright, I updated the PR, was thinking whether I should have |
Nice! Could you add a test to cover this bug? |
Test added |
🎉 This PR is included in version 3.5.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
When initialDataUpdatedAt is a falsy numeric value (e.g. 0), it will cause it to be replaced with Date.now(). This leads to unexpected behaviour, as one would expect the query to be invalidated instantly, if staleTime is set to an amount less than the result of Date.now(). This change will check if the value is numeric, and if so, always use this numeric value.
BREAKING: This changes the behaviour of the plugin for those users that have specified initialDataUpdated at <= 0.