Skip to content

[V7] Suspense Element Not Displaying During Lazy Loading Transition #12474

@vladyslavgeyna

Description

@vladyslavgeyna

I'm using React Router as a...

library

Reproduction

Sample code on CodeSandbox: https://codesandbox.io/p/github/vladyslavgeyna/lazy-loading-test/main?import=true&embed=1

  1. Run the app.
  2. Use the navigation bar on the left to navigate through the pages.
  3. The loading fallback does not mount, but the console statement from the component is displayed.

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1
    Memory: 65.13 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
  Browsers:
    Chrome: 131.0.6778.108
    Safari: 17.5
  npmPackages:
    react-router: ^7.0.2 => 7.0.2 
    vite: ^5.1.4 => 5.4.11

Used Package Manager

npm

Expected Behavior

The loading fallback should appear when navigating between pages using the navigation bar on the left side of the page.

Actual Behavior

When navigating between lazy-loaded routes, the Suspense fallback does not replace the current route while the new component is being loaded.

The issue is observed in version 7 of react-router when the lazy loading is used with Suspense.

At the initial load of the application, the Suspense element functions as expected. However, when navigating to another page that uses lazy loading, the following behavior is observed:

  • The code of the fallback component executes (a console message is logged), but visually, the page remains as it was before the navigation.
  • The new page only becomes visible once it finishes loading, whereas the Suspense element should have been displayed during the transition.
  • Despite this, the URL changes immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions