Skip to content

Throwing notFound() in loader causes infinite "pending" state #1795

Closed

Description

@melv-n

Describe the bug

If you throw notFound() in a loader after a short delay (e.g. when awaiting a request), the parent routes stay forever stuck in "pending" state.

This behaviour does not happen if the loader promise resolves very quick, e.g. within 100ms.

Simplest reproduction:

export const Route = createFileRoute('/posts/$postId')({
  loader: async ({ params }) => {
    try {
      // Simulate a slow request. Resolving this within 100ms works fine, but if it takes longer
      // the route state will be forever stuck in pending.
      await new Promise((resolve, reject) => {
        setTimeout(() => {
          reject();
        }, 1000);
      });
    } catch (err) {
      // Never shows
      throw notFound();
    }
  },

  notFoundComponent: () => <div>Post not found</div>,
});

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-jc3pyp?file=src%2Froutes%2Findex.tsx

Steps to Reproduce the Bug or Issue

  1. Go to /posts/whatever in Stackblitz (posts.$postId.tsx)

Expected behavior

A "Not found message"

Actual behavior

The matched root route is stuck in a pending state according to the dev tools, the final route correctly has "not found" state.

This causes the page to never load.

Platform

  • OS: macOS
  • Browser: Arc (Chrome)
  • Version: 1.47

Additional context

No response

Activity

  1. changed the title [-]Never ending "pending" state when `notFound()` is thrown from a splat route[/-] [+]Application stuck in "pending" state when `notFound()` is thrown from a splat route[/+] on Jun 21, 2024
  2. changed the title [-]Application stuck in "pending" state when `notFound()` is thrown from a splat route[/-] [+]Application stuck in "pending" state when `notFound()` is thrown from a $param route[/+] on Jun 27, 2024
  3. melv-n commented on Jun 27, 2024

    @melv-n
    ContributorAuthor

    @tannerlinsley This is currently very broken, where the router gets forever stuck in a pending state when throw notFound() in any async loader or beforeLoad. Latest TSR version (v1.40.0)

    Simplest repro (updated Stackblitz):

    export const Route = createFileRoute('/posts/$postId')({
      loader: async ({ params }) => {
        try {
          // Simulate a slow request. Resolving this within 100ms works fine, but if it takes longer
          // the route state will be forever stuck in pending.
          await new Promise((resolve, reject) => {
            setTimeout(() => {
              reject();
            }, 1000);
          });
        } catch (err) {
          // Never shows
          throw notFound();
        }
      },
    
      // Expectation: See this component after 1000ms
      notFoundComponent: () => <div>Post not found</div>,
    });
  4. changed the title [-]Application stuck in "pending" state when `notFound()` is thrown from a $param route[/-] [+]Throwing `notFound()` in loader causes infinite "pending" state[/+] on Jul 2, 2024
  5. melv-n commented on Jul 7, 2024

    @melv-n
    ContributorAuthor

    @schiller-manuel Would be amazing if you could confirm this use-case is also solved by #1907 😍

  6. schiller-manuel commented on Jul 7, 2024

    @schiller-manuel
    Collaborator

    not solved (yet) unfortunately

  7. added a commit that references this issue on Jul 8, 2024
    752a136
  8. tannerlinsley commented on Jul 8, 2024

    @tannerlinsley
    Member

    This will be fixed in 752a136

  9. added
    bug
    on Jul 11, 2024
  10. myeljoud commented on May 29, 2025

    @myeljoud
    Contributor

    I still have the same issue now

  11. schiller-manuel commented on May 29, 2025

    @schiller-manuel
    Collaborator

    @myeljoud please create a new GitHub issue including a complete minimal example

  12. natedunn commented on Dec 9, 2025

    @natedunn

    I am getting something similar but I can't seem to reproduce. I am very sad and tired. Just in my project. 😞

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions