Skip to content
Source
Sign inSign up
TanStack/router

Error component is not displayed when an error is thrown by beforeLoad on the first access screen #2006

Send to my agent
ClosedFiNGAHOLiC(GitHub profile, opens in a new tab) opened this issue 5 comments

Describe the bug

If an error is thrown by beforeLoad on the screen after the page is moved, the error component is displayed.

  • Incidentally, there is also a problem that the error component remains displayed when returning with the back button of the browser, although this is not the main issue.

However, on the screen at the first access, the error component is not displayed even if an error is thrown by beforeLoad.

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

export const Route = createFileRoute('/test/')({
  beforeLoad: async () => {
    await new Promise((resolve) => setTimeout(resolve, 1000));

    // If an error is thrown by beforeLoad on the screen after the page is moved, the error component is displayed.
    // However, on the screen at the first access, the error component is not displayed even if an error is thrown by beforeLoad.
    throw new Error('error');
  },
});

Your Example Website or App

https://stackblitz.com/edit/vitejs-vite-ptbzxn

Steps to Reproduce the Bug or Issue

  1. Open the StackBlitz reproduction and open preview in new tab
  2. Click [test]
  3. Error component is displayed on Test Page
  4. Refresh Page on Test Page
  5. Error component is not displayed on Test Page

Expected behavior

The error component should be displayed if an error is thrown by beforeLoad, even on the first access.

Screenshots or Videos

No response

Platform

  • OS: any
  • Browser: any
  • Version: latest

Additional context

No response

  1. SeanCassiere added labelsbug

  2. Do we have a failing test we could add for this?

  3. SeanCassierecommented

    @tannerlinsley got tests for this in https://github.com/TanStack/router/pull/2040

  4. I think the same issue happens when an error is thrown in shouldReload().

Sign in to join this conversation.