Fix misc hydration bugs - #9157
Conversation
* Do not hydrate older promises * Do not infinite loop on hydrating failed promises * Hydrate already resolved promises immediately
|
View your CI Pipeline Execution ↗ for commit fd7a6e0.
☁️ Nx Cloud last updated this comment at |
* Include dehydratedAt and ignore hydrating old promises * This is an approximation of dataUpdatedAt, but is not perfect * Refactor checks for if we should hydrate promises or not to fix infinite loop bug on failed queries * Hydrate already resolved promises synchronously
27d8d67 to
13c3232
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9157 +/- ##
===========================================
+ Coverage 45.00% 59.46% +14.46%
===========================================
Files 206 138 -68
Lines 8219 5482 -2737
Branches 1836 1471 -365
===========================================
- Hits 3699 3260 -439
+ Misses 4080 1925 -2155
+ Partials 440 297 -143 🚀 New features to boost your workflow:
|
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| ?.catch(() => {}) |
There was a problem hiding this comment.
using noop from query-core should get rid of the eslint-disable:
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | |
| ?.catch(() => {}) | |
| ?.catch(noop) |
There was a problem hiding this comment.
It doesn't get rid of the lint warning unfortunately, that's warning about the "unnecessary" ?. here (this is typed as a promise, but might be a kind of thenable without .catch).
Still a good idea to use the noop, and I updated the comment to mention .catch specifically to make it a tiny bit clearer.
|
Is this going to be a part of next release? |
|
It's already released |
… branch (P4-1) The whole-client hydrate() new-query build branch forced `status: data !== undefined ? 'success' : state.status`, which silently rewrote a restored error-with-data snapshot (a refetch error) or a pending-with-data snapshot into a clean 'success'. This dropped the persisted error/pending status and made `isRefetchError` false on restore, diverging from the fine-grained one-at-a-time (Query.fetch adoption) and bulk (restoreQueries) restore paths, which both adopt the persisted status verbatim. Fix: only force 'success' when the snapshot carried no data of its own (`state.data === undefined`) but a resolved streamed promise supplied `data` (preserving the TanStack#9157 resolved-promise behavior); otherwise preserve the persisted `state.status`. This makes all three restore paths deterministic (R2) and keeps full observable state on restore (R1/R4), applying to every status value (C2). Adds an isolated, add-only regression test (C7) covering error-with-data -> refetch error, pending-with-data -> pending, error-without-data, success control, and a streamed-promise pending -> success guard. Addresses QA finding P4-1 (Final Acceptance report).
This PR:
At the point of hydrating a promise, we don't know when the promise will finish, that is, we don't know the
dataUpdatedAtof the hydrated query, so we can't compare that to the existing query. The PR sidesteps this by introducingdehydratedAtas an approximation. This is not perfect, but is an improvement.To fix the infinite loop bug I also opted to never hydrate promises if the existing query is already pending, as there is no way to know which of these pending queries will finish first or have the newest data. We could do fancier things like a
Promise.raceand use whatever finishes first, but that seemed like overengineering at this point.