router icon indicating copy to clipboard operation
router copied to clipboard

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

Open FiNGAHOLiC opened this issue 1 year ago • 4 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

FiNGAHOLiC avatar Jul 22 '24 08:07 FiNGAHOLiC

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

tannerlinsley avatar Jul 26 '24 20:07 tannerlinsley

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

SeanCassiere avatar Jul 27 '24 09:07 SeanCassiere

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

lo1tuma avatar Aug 21 '24 08:08 lo1tuma

any updates?

FiNGAHOLiC avatar Sep 21 '24 04:09 FiNGAHOLiC

fixed this in https://github.com/TanStack/router/releases/tag/v1.74.6

schiller-manuel avatar Oct 21 '24 20:10 schiller-manuel