Skip to content

fix(infinite): keep parallel getKey previousPageData null on setSize#4253

Open
li-jia-nan wants to merge 3 commits into
vercel:mainfrom
li-jia-nan:infinite-fix
Open

fix(infinite): keep parallel getKey previousPageData null on setSize#4253
li-jia-nan wants to merge 3 commits into
vercel:mainfrom
li-jia-nan:infinite-fix

Conversation

@li-jia-nan
Copy link
Copy Markdown

@li-jia-nan li-jia-nan commented May 9, 2026

When useSWRInfinite runs with parallel enabled, getKey should always receive null as previousPageData because pages are independent. setSize previously recomputed page keys using the previous page data, which could produce keys inconsistent with the initial parallel load.

Update setSize to pass null in parallel mode and add a regression test.

Copilot AI review requested due to automatic review settings May 9, 2026 03:09
@li-jia-nan li-jia-nan requested review from huozhi and shuding as code owners May 9, 2026 03:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes useSWRInfinite key recomputation during setSize when parallel: true, ensuring getKey continues to receive previousPageData = null (since pages are independent in parallel mode). It also adds a regression test to prevent key mismatches between the initial parallel load and subsequent setSize calls.

Changes:

  • Update setSize to call getKey(i, null) in parallel mode and avoid updating previousPageData.
  • Tighten typing for internal arrays used during parallel revalidation.
  • Add a regression test covering setSize behavior with parallel: true.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/infinite/index.ts Adjusts setSize page-key recomputation to respect parallel semantics (no previousPageData).
test/use-swr-infinite.test.tsx Adds a regression test intended to assert previousPageData remains null after calling setSize in parallel mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/use-swr-infinite.test.tsx
Comment thread test/use-swr-infinite.test.tsx
Comment thread src/infinite/index.ts
@li-jia-nan
Copy link
Copy Markdown
Author

@shuding @huozhi Hi, could you please review this PR when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants