Repository navigation
Conversation
…refetch and `fetchNextPage` A call-site `initialPageParam` was only on the first request's arg. When that first page failed there were no cached `pageParams` to start from, so `refetch()`, `fetchNextPage()`, polling and invalidation fell back to the endpoint's `initialPageParam`. The pending reducer now keeps it on the cache entry, like `direction`, and the thunk reads it from there.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@reduxjs/rtk-codemods
@rtk-query/codegen-openapi
@rtk-query/graphql-request-base-query
@reduxjs/toolkit
commit: |
If an infinite query is started with a call-site
initialPageParam(theuseInfiniteQueryoption, orinitiate(arg, { initialPageParam })) and its first page fails, the nextrefetch()orfetchNextPage()asks for the endpoint'sinitialPageParaminstead. Polling and tag invalidation do the same.The call-site value only rides on the first request's arg.
refetchre-dispatches without it (buildInitiate.ts#L630-L636), and the hook'sfetchNextPagetrigger passes onlydirection. With no cached pages, the thunk falls back to the endpoint default (buildThunks.ts#L798-L805):Once a page has loaded you never see it, because
cachedPageParams[0]wins. So it only bites after a failed first page.The pending reducer now keeps a defined
initialPageParamon the infinite query cache entry, next todirection(writePendingCacheEntryin buildSlice.ts). An undefined value doesn't overwrite it, the same ruleoriginalArgsuses, since every refetch passesinitialPageParam: undefined. The thunk reads it off the entry (it already reads the entry forcachedData), andInfiniteQuerySubStategetsinitialPageParam?: PageParamFrom<D>. It's one place, so refetch,fetchNextPage, polling, focus/reconnect and invalidation all pick it up.A query that never passed a value still uses the endpoint default. A later explicit value replaces the stored one. The stored value belongs to the cache entry, so a second subscriber on the same key with no value of its own also starts from it after a failed first page (which is what already happens once a page is cached, via
pageParams[0]).Tests: a
test.each(['refetch', 'forward fetch'])ininfiniteQueries.test.ts, on the existingmakeInfiniteApi({ failOnHit: 1 })fixture. Endpoint default 0,initiate('x', { initialPageParam: 5 }), first page fails, thenrefetch()orinitiate('x', { direction: 'forward' })(whatfetchNextPagedispatches). Both fail on master:I also tried the hook path with a throwaway
useInfiniteQuery('x', { initialPageParam: 5 })spec:refetch()andfetchNextPage()each request[5, 5]with the fix. The wholepackages/toolkitsuite passes with--typecheck(114 files, 1826 passed, 2 todo), and oxfmt and oxlint are clean.There's no issue for this one.