Skip to content

useInfiniteQuery + experimental_prefetchInRender uses error boundary for subsequent pages #9938

@OliverJAsh

Description

@OliverJAsh

Describe the bug

Both useSuspenseInfiniteQuery and useInfiniteQuery + experimental_prefetchInRender use the error boundary for the first page, but only the latter uses the error boundary for subsequent pages.

useSuspenseInfiniteQuery (doesn't use error boundary):

Screen.Recording.2025-12-02.at.16.17.58.mov

useInfiniteQuery + experimental_prefetchInRender (uses error boundary):

Screen.Recording.2025-12-02.at.16.17.28.mov

Is this intentional? It was really surprising to me. I would expect both of these hooks to behave the same.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-qags2jzf?file=src%2Fcomponents%2FProjects.tsx&preset=node

Steps to reproduce

  1. Click "Show Projects" (fetches first page successfully)
  2. Click "Fetch next" (fetches second page which results in an error)

Switch between the two examples to observe the behaviour difference:

  // ✅ Uses error boundary for first page
  // ✅ Uses error boundary for subsequent pages
  const { promise, fetchNextPage, isError } = useInfiniteQuery({
    queryKey: ['projects'],
    queryFn: fetchProjects,
    initialPageParam: 1,
    getNextPageParam: (a, b, l) => l + 1,
    experimental_prefetchInRender: true,
  });
  const data = React.use(promise);

  // // ✅ Uses error boundary for first page
  // // ❌ Does not use the error boundary for subsequent pages
  // const { data, fetchNextPage, isError } = useSuspenseInfiniteQuery({
  //   queryKey: ['projects'],
  //   queryFn: fetchProjects,
  //   initialPageParam: 1,
  //   getNextPageParam: (a, b, l) => l + 1,
  // });

Expected behavior

I would expect both of these hooks to behave the same.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

N/A

Tanstack Query adapter

None

TanStack Query version

5.90.11

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions