Skip to content

RouterProvider inside Suspense shows hydrateFallback forever #14356

@tommie-lie

Description

@tommie-lie

Reproduction

Go to https://codesandbox.io/p/devbox/lfpmvq?file=%2Fsrc%2FApp.jsx%3A36%2C28.
The site should say "Hydrating...", if not, try reloading a few times.

The error goes away if either:

  • the loader in line 33 is slower, e.g. sleep(300)
  • the component does not suspend, so the use(serviceDataPromise) line is commented out

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (2) x64 AMD EPYC
    Memory: 1.22 GB / 4.01 GB
    Container: Yes
    Shell: Unknown
  Binaries:
    Node: 20.12.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/share/npm-global/bin/pnpm
  npmPackages:
    react-router: ^7.9.1 => 7.9.1 
    vite: ^6.0.3 => 6.3.5

Used Package Manager

pnpm

Expected Behavior

The AppRoutes component suspends and the user sees "Loading...". After 100ms the Promise resolves and AppRoutes renders a RouterProvider and all the loaders start running. While the loaders are running, the hydration fallback "Hydrating..." is shown.
After all loaders in the routes finish, the route's content should be displayed, in the MWE this would be Content.

Actual Behavior

In most cases (not consistent, as I suspect a race somehwere, but on my machine like 90% of the time), after the promise resolves and the router is rendered, I see "Hydrating..." forever and never the "Content".

In my real application, the loader actually loads data from the network and depending on how fast the request is, the application either works perfectly, or stalls forever. It took me a while to figure out that fast requests cause the application to fail ;-)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions