fix(base-data-service): adapt to @tanstack/query-core v5 API - #9712
fix(base-data-service): adapt to @tanstack/query-core v5 API#9712cryptodev-2s wants to merge 8 commits into
@tanstack/query-core v5 API#9712Conversation
def5a29 to
88ec84f
Compare
637de58 to
6dbe63d
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
… param callbacks query-core v5 walks `getNextPageParam` when it refetches an infinite query that has more than one page cached. Consumers that paginate by explicit cursor without defining `getNextPageParam` (like `MoneyAccountApiDataService`) would throw once a second page was cached and a stale refetch with no page param ran. Default `getNextPageParam` to a resolver that returns `null` so the refetch rebuilds just the first page instead of throwing. The consumer repopulates the cache by navigating again with explicit page params. Also adds a `fetchInfiniteQuery` test suite covering forward and backward navigation with and without page param callbacks, single page returns, `staleTime` deduplication, and this refetch regression. Flagged by Cursor Bugbot on #9712.
A recent PR updated this package to v5 in one package (#9563). This PR updates to v5 in all remaining packages.
The v5 bump updated the package.json versions but left the v4 API usage in place, so the build fails. This adapts the code to v5. * `invalidateQueries` filter: the generic is now the query key (not page data), so drop the `Json` argument * handle the new `skipToken` sentinel by typing `queryFn` as a concrete function (data services never use it) * `fetchInfiniteQuery`: pass `initialPageParam` and inject page param resolvers at fetch time, since v5 no longer accepts an explicit `pageParam` via `fetchMore` meta. This keeps cursor pagination working for consumers that do not define page param callbacks * chomp: `cacheTime` is now `gcTime` * tests: `hashQueryKey` is now `hashKey`, and `dehydrate` adds a `dehydratedAt` field
… param callbacks query-core v5 walks `getNextPageParam` when it refetches an infinite query that has more than one page cached. Consumers that paginate by explicit cursor without defining `getNextPageParam` (like `MoneyAccountApiDataService`) would throw once a second page was cached and a stale refetch with no page param ran. Default `getNextPageParam` to a resolver that returns `null` so the refetch rebuilds just the first page instead of throwing. The consumer repopulates the cache by navigating again with explicit page params. Also adds a `fetchInfiniteQuery` test suite covering forward and backward navigation with and without page param callbacks, single page returns, `staleTime` deduplication, and this refetch regression. Flagged by Cursor Bugbot on #9712.
4561b46 to
5a1dcce
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5a1dcce. Configure here.
| // query-core v5 requires an `initialPageParam`. When the caller drives | ||
| // pagination with an explicit `pageParam`, use it as the initial param | ||
| // so the first (and only) page fetched is the requested one. | ||
| initialPageParam: (options.initialPageParam ?? pageParam) as TPageParam, |
There was a problem hiding this comment.
Null initial page param discarded
Medium Severity
initialPageParam is resolved with ??, so an explicit null is treated as missing and replaced by pageParam or undefined. null is a valid Json page param and the usual v5 first-page sentinel, so callers that set initialPageParam: null never get that value stored or passed through.
Reviewed by Cursor Bugbot for commit 5a1dcce. Configure here.


What
Stacked on top of #9686. That PR bumps
@tanstack/query-corethis adapts the code to v5.Changes
packages/base-data-service/src/BaseDataService.tsinvalidateQueriesfilter type: in v5 the generic is the query key (constrained toreadonly unknown[]), not page data, soInvalidateQueryFilters<Json>no longer type checks. Dropped the argument to keep the loose v4 ergonomics.queryFncan now be theskipTokensentinel (aunique symbol, not callable). Typed the options soqueryFnis always a concrete function, since data services never useskipToken.fetchInfiniteQuery: v5 requiresinitialPageParam, andfetchMoremeta no longer carries an explicitpageParam(v5 derives it fromgetNextPageParam/getPreviousPageParam). Now passesinitialPageParamand injects page param resolvers atquery.fetchtime so pagination still fetches the exact requested page. This keeps cursor pagination working even for consumers that do not define page param callbacks.packages/chomp-api-service/src/chomp-api-service.tscacheTimewas renamed togcTimein v5. Without this, the "evict on settle" behavior stopped working.Tests / helpers
hashQueryKeywas renamed tohashKey.dehydratenow writes adehydratedAtfield into query state.cacheTimetogcTimeand typed the page param in the example service.Why the injection matters
MoneyAccountApiDataServicepaginates via an explicit cursor without defininggetNextPageParam. Under the raw v5 bump its pagination test crashed withoptions.getNextPageParam is not a function. The resolver injection restores that behavior.Note
Medium Risk
Breaking dependency and API surface on shared BaseDataService pagination/cache behavior; incorrect infinite-query shims could regress cursor paging or cache eviction for multiple API services.
Overview
Breaking upgrade of
@tanstack/query-corefrom v4 to v5 acrossbase-data-serviceand dependent packages (chomp-api, money-account-api, sentinel, sample-controllers, wallet-framework-docs).BaseDataServiceis updated so query APIs match v5:invalidateQueriesno longer uses the oldInvalidateQueryFilters<Json>typing;fetchQuery/fetchInfiniteQueryrequire a realqueryFn(v5’sskipTokenis excluded).fetchInfiniteQueryis reworked for v5’s infinite-query rules—initialPageParamis supplied, and because v5 no longer passes an explicit page viafetchMoremeta, the base layer injectsgetNextPageParam/getPreviousPageParamat fetch time (plus a no-op next-page resolver when callers omit callbacks) so explicit cursor pagination still works for services like Money Account API that don’t define page-param callbacks.Downstream call sites rename
cacheTime→gcTime(e.g. ChompgetAssociatedAddresseseviction). Tests switchhashQueryKey→hashKey, expectdehydratedAton persisted queries, and add dedicatedfetchInfiniteQuerycoverage for forward/backward paging with and without callbacks.Reviewed by Cursor Bugbot for commit 5a1dcce. Bugbot is set up for automated code reviews on this repo. Configure here.