Skip to content

Router defaultPendingComponent Not effective(version:1.121.24) #4467

Closed

Description

@yibird

Which project does this relate to?

Router

Describe the bug

import {
  createRootRoute,
  createRouter,
  lazyRouteComponent,
  RouterProvider
} from '@tanstack/react-router'

function Loading() {
  return (
    <div
      style={{
        position: 'fixed',
        left: 0,
        top: 0,
        backgroundColor: 'red',
        width: '100%',
        height: '100%'
      }}
    >
      loading
    </div>
  )
}

const RootRoute = createRootRoute({
  component: lazyRouteComponent(() => import('./Comp01')),
  pendingComponent: Loading
})

function RouterApp() {
  const router = createRouter({
    routeTree: RootRoute,
    defaultPreload: 'intent',
    scrollRestoration: true,
    defaultPendingComponent: Loading
  })
  return <RouterProvider router={router} />
}

export default function Demo() {
  return <RouterApp />
}

Your Example Website or App

code route

Steps to Reproduce the Bug or Issue

import {
  createRootRoute,
  createRouter,
  lazyRouteComponent,
  RouterProvider
} from '@tanstack/react-router'

function Loading() {
  return (
    <div
      style={{
        position: 'fixed',
        left: 0,
        top: 0,
        backgroundColor: 'red',
        width: '100%',
        height: '100%'
      }}
    >
      loading
    </div>
  )
}

const RootRoute = createRootRoute({
  component: lazyRouteComponent(() => import('./Comp01')),
  pendingComponent: Loading
})

function RouterApp() {
  const router = createRouter({
    routeTree: RootRoute,
    defaultPreload: 'intent',
    scrollRestoration: true,
    defaultPendingComponent: Loading
  })
  return <RouterProvider router={router} />
}

export default function Demo() {
  return <RouterApp />
}

Expected behavior

I hope there will be a loading effect when refreshing the webpage, but now the loading component is not working. I don't know if what I wrote is correct, but I am referring to the example on the official website

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Activity

  1. leesb971204 commented on Jun 20, 2025

    @leesb971204
    Contributor

    Even if a beforeLoad or loader exists on the root route, the PendingComponent is not displayed.

  2. schiller-manuel commented on Jun 20, 2025

    @schiller-manuel
    Collaborator

    does this need wrapInSuspense:true on the root node?

  3. yibird commented on Jun 20, 2025

    @yibird
    Author

    does this need wrapInSuspense:true on the root node?

    I have used it, but it has no effect

  4. yibird commented on Jun 20, 2025

    @yibird
    Author
    const RootRoute = createRootRoute({
    component: lazyRouteComponent(() => import('./Comp01')),
    pendingComponent: Loading,
    loader: () => new Promise((resolve) => setTimeout(resolve, 1000))
    })

    Setting the loader is effective, but I expect it to display 'pending component' instead of 'white screen' during route loading

  5. schiller-manuel commented on Jun 20, 2025

    @schiller-manuel
    Collaborator

    do we have an example that is using a lazy root component? I am not sure this is supported

  6. leesb971204 commented on Jun 20, 2025

    @leesb971204
    Contributor

    It doesn’t seem to be an issue with the lazy component.
    Even when defining the component without using lazy, the pendingComponent defined in createRootRoute doesn’t render.
    However, the defaultPendingComponent does render.

    Also, for me, wrapInSuspense: true does have an effect. why?

  7. mversic commented on Jul 15, 2025

    @mversic

    It doesn’t seem to be an issue with the lazy component.

    t is my observation that the pending component is not having effect on lazy routes.

    Even when defining the component without using lazy, the pendingComponent defined in createRootRoute doesn’t render.

    yes, it's possible that it's also not working for root route in general. You should try using a pending component on a lazy route that is not root route to observe the bug

  8. schiller-manuel commented on Jul 15, 2025

    @schiller-manuel
    Collaborator

    @mversic can you please provide a complete minimal reproducer?

  9. leesb971204 commented on Jul 16, 2025

    @leesb971204
    Contributor

    It doesn’t seem to be an issue with the lazy component.

    t is my observation that the pending component is not having effect on lazy routes.

    Even when defining the component without using lazy, the pendingComponent defined in createRootRoute doesn’t render.

    yes, it's possible that it's also not working for root route in general. You should try using a pending component on a lazy route that is not root route to observe the bug

    I’m not entirely sure if I understood everything correctly, but it seems like the bug does not occur on lazy route that are not the root route.

    I created two test cases:
    1. When the root route is lazy (https://stackblitz.com/edit/tanstack-router-yetyygmq?file=src%2Fmain.tsx)
    2. When a non-root route is lazy (https://stackblitz.com/edit/tanstack-router-t3j5bz2q?file=src%2Froutes%2Fabout.tsx)

    Here’s the summary of what I observed:

    ⸻

    When the root route is lazy:
    1. If only loader is defined → defaultPendingComponent is shown
    2. If both loader and wrapInSuspense are set → the route’s own pendingComponent is shown
    3. If only wrapInSuspense is defined → no pendingComponent is shown
    4. If neither is set → no pendingComponent is shown
    ⸻

    When a non-root route is lazy:
    Even without defining a loader, the route’s own pendingComponent is displayed - In fact, even if you remove the loader from the about route in the second link, the pendingComponent still displays correctly when navigating to the about page.

    Please let me know if I’m misunderstanding anything!

  10. goatrenterguy commented on Jan 14, 2026

    @goatrenterguy

    Running into the same issue on 1.149.3. Adding loader: () => {} to each lazy route fixes it but this is not an ideal solution

  11. deivisonrpg commented on Apr 15, 2026

    @deivisonrpg

    Same here with 1.168.2 . Adding loader: () => {} to each lazy route fixes it.

  12. schiller-manuel commented on Apr 15, 2026

    @schiller-manuel
    Collaborator

    @deivisonrpg do you have a lazy root route? this is not supported (and doesnt make sense IMO as it will be loaded always )

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

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