Skip to content

Error: "reject is not a function" in Next.js 14 App Router with HydrationBoundary #9232

Closed
@jjmean2

Description

@jjmean2

Describe the bug

I encountered an error when using React Query prefetching in a Next.js app with the App Router.
The official example works with Next.js 15, but running the same example on Next.js 14 causes an error if the prefetched query fails before hydration.

In Next.js 14, if a prefetched query fails quickly and HydrationBoundary tries to hydrate that query, the following error occurs:

reject is not a function

d8cf6a2e-5ca6-4ad5-957e-212a1c9718d3

Here’s a CodeSandbox that reproduces the issue:
https://codesandbox.io/p/devbox/gifted-framework-fycm7x?workspaceId=ws_JRuwL4n9AbbzLmYKLLAozM

The error seems to originate from this line in React:

Chunk.prototype.then = function <T>(
  this: SomeChunk<T>,
  resolve: (value: T) => mixed,
  reject: (reason: mixed) => mixed,
) {

    // ... omit

    default:
      // 👇 reject is not a function!
      reject(chunk.reason);
      break;

This code assumes the reject callback is always defined. However, tryResolveSync currently does not pass the reject argument to .then().

This issue does not occur in Next.js 15, which uses a different implementation.
It seems that this code in React is what Next.js 15 uses instead:

    default:
      if (reject) {
        reject(chunk.reason);
      }
      break;

Although .catch() is also present in tryResolveSync, it’s not sufficient for environments that rely on the second argument to .then() for error handling (like the one shown above).

I think simply passing a noop callback as the second argument to the .then() method resolves this issue.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/gifted-framework-fycm7x?workspaceId=ws_JRuwL4n9AbbzLmYKLLAozM

Steps to reproduce

  1. Visit the reproducible example site
  2. The error saying "TypeError: reject is not a function" occurs

Expected behavior

I expect the error to say “no user”, because that’s what the queryFn throws, but instead it says: "TypeError: reject is not a function".

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 136.0.7103.114

Tanstack Query adapter

react-query

TanStack Query version

5.77.2

TypeScript version

v5.8.3

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