Skip to content
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(query-core): abort fetch loop for infinite queries if getNextPageParam returns null or undefined #7799

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Jul 26, 2024

The fetchPage function has a safeguard where it only returns the current data if pageParam == null, however, this means we still stay in the loop and call getNextPageParam unnecessarily.

This can be troublesome if you set pages: Infinity on queryClient.fetchInfiniteQuery to fetch an arbitrary amount of pages until the natural end is reached by returning null/undefined from getNextPageParam, because it would never actually escape the loop

…Param returns null or undefined

The `fetchPage` function has a safeguard where it only returns the current data if pageParam == null, however, this means we still stay in the loop and call `getNextPageParam` unnecessarily.

This can be troublesome if you set `pages: Infinity` on queryClient.fetchInfiniteQuery to fetch an arbitrary amount of pages until the natural end is reached by returning null/undefined from getNextPageParam, because it would never actually escape the loop
@TkDodo TkDodo marked this pull request as ready for review July 26, 2024 08:30
Copy link

nx-cloud bot commented Jul 26, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5056b10. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link

pkg-pr-new bot commented Jul 26, 2024

commit: 5056b10

pnpm add https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@7799
pnpm add https://pkg.pr.new/@tanstack/angular-query-experimental@7799
pnpm add https://pkg.pr.new/@tanstack/eslint-plugin-query@7799
pnpm add https://pkg.pr.new/@tanstack/query-async-storage-persister@7799
pnpm add https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@7799
pnpm add https://pkg.pr.new/@tanstack/query-core@7799
pnpm add https://pkg.pr.new/@tanstack/query-devtools@7799
pnpm add https://pkg.pr.new/@tanstack/query-persist-client-core@7799
pnpm add https://pkg.pr.new/@tanstack/query-sync-storage-persister@7799
pnpm add https://pkg.pr.new/@tanstack/react-query@7799
pnpm add https://pkg.pr.new/@tanstack/react-query-devtools@7799
pnpm add https://pkg.pr.new/@tanstack/react-query-next-experimental@7799
pnpm add https://pkg.pr.new/@tanstack/react-query-persist-client@7799
pnpm add https://pkg.pr.new/@tanstack/solid-query@7799
pnpm add https://pkg.pr.new/@tanstack/solid-query-devtools@7799
pnpm add https://pkg.pr.new/@tanstack/solid-query-persist-client@7799
pnpm add https://pkg.pr.new/@tanstack/svelte-query@7799
pnpm add https://pkg.pr.new/@tanstack/svelte-query-devtools@7799
pnpm add https://pkg.pr.new/@tanstack/svelte-query-persist-client@7799
pnpm add https://pkg.pr.new/@tanstack/vue-query@7799
pnpm add https://pkg.pr.new/@tanstack/vue-query-devtools@7799

Open in Stackblitz

More templates

@TkDodo TkDodo merged commit 3ef7887 into main Jul 26, 2024
8 checks passed
@TkDodo TkDodo deleted the feature/infinite-query-early-abort branch July 26, 2024 08:44
@mrlubos
Copy link

mrlubos commented Jul 26, 2024

Thank you for the quick fix!

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

Successfully merging this pull request may close these issues.

2 participants