Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

How to disable default error boundary component? #3389

Unanswered
hihhhello asked this question in Q&A
Discussion options

Duplicating StackOverlow questions regarding a default Error Boundary.

Question
Is there a way to disable the default error boundary component/behavior?

image

Example:

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

import { useAuth } from '@/components/auth-provider';
import { RootLayout } from '@/components/root-layout';
import { StoryOwnerPage } from '@/components/story-owner-page';
import { storyByIdQueryOptions } from '@/shared/queries';

export const Route = createFileRoute('/stories_/$storyId')({
  loader: ({ context: { queryClient }, params: { storyId } }) => {
    return queryClient.ensureQueryData(storyByIdQueryOptions(storyId));
  },
  component: RouteComponent,
});

function RouteComponent() {
  const { storyId } = Route.useParams();

  const auth = useAuth();

  if (auth.isError) {
    return <>Story Guest Page</>;
  }

  return (
    <RootLayout>
      <StoryOwnerPage storyId={storyId} />
    </RootLayout>
  );
}

I want to skip the error that is thrown from the loader and still render RouteComponent to show the guest page instead.

You must be logged in to vote

Replies: 1 comment

Comment options

In my case it worked using async/await with an try/catch wrapping the ensureQueryData-call:

  loader: async ({ context: { queryClient }, params: { storyId } }) => {
    try {
        await queryClient.ensureQueryData(storyByIdQueryOptions(storyId));
    } catch {
        // Catch and suppress the error, delegating error handling to ErrorBoundary inside of route component, triggered by useSuspenseQuery-calls within
    }
  },
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.