Skip to content
Source
Sign inSign up
TanStack/router

AbortController is not properly caught in parent loader #3928

Closedbrmzkw(GitHub profile, opens in a new tab) opened this issue 5 comments

Which project does this relate to?

Router

Describe the bug

First of all, I'm sorry if the title of the issue does not describe what is happening.

I have two routes:

  • the __root route with a loader performing a call to fetch to a slow API
  • an index route with a loader also performing a call to fetch to a slow API

Both calls forward the abortController.signal to fetch to ensure the request is canceled if necessary.

The index route is displaying a text input, and whenever the user types something, navigate is used which triggers a route reload.

If too many reloads are run, the error message "signal is aborted without reason" is triggered from the root view.

Your Example Website or App

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

Steps to Reproduce the Bug or Issue

  1. write one character at a time in the text input: it works well
  2. write many characters simultaneously: an error is triggered

Expected behavior

The abort error should be caught.

Screenshots or Videos

https://github.com/user-attachments/assets/5d7b1eec-2be8-4059-8d4d-1bafe606c05f

Platform

Additional context

root.tsx:

import * as React from 'react';
import { Link, Outlet, createRootRoute } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools';

export const Route = createRootRoute({
  component: RootComponent,

  loader: async ({ abortController }) => {
    try {
      const data = await fetch('https://httpstat.us/200?sleep=1000', {
        signal: abortController.signal,
      });
    } catch (e) {
      console.log('in __root, aborted');
      throw e;
    }
  },
});

function RootComponent() {
  return (
    <>
      <div className="p-2 flex gap-2 text-lg">
        <Link
          to="/"
          activeProps={{
            className: 'font-bold',
          }}
          activeOptions={{ exact: true }}
        >
          Home
        </Link>{' '}
        <Link
          to="/about"
          activeProps={{
            className: 'font-bold',
          }}
        >
          About
        </Link>
      </div>
      <hr />
      <Outlet />
      <TanStackRouterDevtools position="bottom-right" />
    </>
  );
}

index.tsx:

import * as React from 'react';
import { createFileRoute } from '@tanstack/react-router';

type Search = {
  filter: string;
};

export const Route = createFileRoute('/')({
  component: HomeComponent,

  validateSearch: (search: Record<string, unknown>): Search => {
    return {
      filter: (search.filter as string) || '',
    };
  },

  loaderDeps: ({ search }) => {
    return {
      filter: search.filter,
    };
  },

  loader: async ({ deps, abortController }) => {
    console.log('loading', deps.filter);
    try {
      const data = await fetch('https://httpstat.us/200?sleep=1000', {
        signal: abortController.signal,
      });
    } catch (e) {
      console.log('in index, signal aborted for', deps.filter);
      throw e;
    }

    console.log('loaded:', deps.filter);
    return { status: 'loaded: ' + deps.filter };
  },
});

function HomeComponent() {
  const search = Route.useSearch();
  const navigate = Route.useNavigate();
  const data = Route.useLoaderData();

  return (
    <div className="p-2">
      <h3>Welcome Home!</h3>

      <h4>Status: {data.status}</h4>

      <input
        className="bg-gray-300 border border-black"
        value={search.filter}
        onChange={(e) => {
          navigate({
            to: '/',
            search: {
              filter: e.target.value,
            },
          });
        }}
      />
    </div>
  );
}
  1. Thanks for the detailed reproduction. I re-ran the rapid search-update sequence on current main, including a root loader and child loaders that forward abortController.signal to an abortable request.

    Superseded child requests are aborted, but their AbortErrors no longer become route errors. The root loader stays successful and its signal is not aborted during the reload churn.

    This appears fixed on current main. If you notice anything differently, please open another issue with a repro :)

  2. @LadyBluenotes thank you so much for the follow-up here.

    My team has been living with this for a while. We started wiring router abort signals into our fetch layer in early 2025, and by September we’d had to stop forwarding the signal because AbortErrors were turning into route errors. Since then we’ve periodically flipped it back on whenever we thought an upstream fix had landed, then off again when it still broke, while chasing the related issues/PRs we hoped would close it out:

    We hadn’t noticed this might be fixed until your message today (we’re subscribed here). Hoping to finally drop the workaround after ~10 months.

    Because it’s been so elusive for us, we’d love to take a closer look at the change that made it so:

    AbortErrors no longer become route errors.

    If you happen to know where that landed, can you link to it? That would be a big help!

  3. LadyBluenotes(GitHub profile, opens in a new tab)commented

    @lnhrdt - my apologies i got some things mixed up. This isn't fixed yet but we have a PR incoming soon (possibly this week?) that will address it (#7805)

  4. Thanks @LadyBluenotes! I see #7814 was closed without merging. We'll watch for a follow-up, but if you get a chance, would you mind dropping a note here when the next PR is up?

  5. Thanks @LadyBluenotes! I see #7814 was closed without merging. We'll watch for a follow-up, but if you get a chance, would you mind dropping a note here when the next PR is up?

    Ha, i referenced the one I did. Should make sure I wake up before sending comments out.

    I updated the comment, but I meant #7805 which now tags this issue. You should be notified once it's merged in (I also double checked and they'll be doing a test to monitor any regressions). They're doing a rewrite so hopefully that ends up helping everything you've been seeing!

Sign in to join this conversation.