Skip to content

componentStack is not available to errorComponent or defaultErrorComponent #2512

Closed as not planned

Description

@absassi

Which project does this relate to?

Router

Describe the bug

Even though info?: { componentStack: string; } appears in ErrorComponentProps, it is never passed to the error component.
The error info with the component stack is captured though, as it is logged to the console as warning and it is passed to onCatch and defaultOnCatch.

Your Example Website or App

https://stackblitz.com/edit/github-ktjn1n-i4bu1m?file=src%2Fmain.tsx,src%2Froutes%2Fabout.tsx

Steps to Reproduce the Bug or Issue

  1. Create an error component that attempts to render the component stack:
function CustomErrorComponent({ error, info }: ErrorComponentProps) {
  return (
    <div>
      <p>{error.message}</p>
      <div>
        <b>Stack:</b>
        <pre>{error.stack}</pre>
      </div>
      <div>
        <b>Component stack:</b>
        <pre>{info?.componentStack}</pre>
      </div>
    </div>
  );
}
  1. Register it as defaultErrorComponent:
const router = createRouter({ routeTree, defaultErrorComponent: CustomErrorComponent });
  1. Throw an error in some route.
  2. Navigate to that route and see that the component stack is undefined.

In the linked MCVE example, the about route is throwing an error. Opening the link and navigating to the About page will reproduce this.

Expected behavior

The same errorInfo with the component stack that is passed to onCatch as its second parameter would also be passed to the error component in the info prop.

Screenshots or Videos

No response

Platform

  • OS: WSL
  • Browser: Edge
  • Version: 1.64.0

Additional context

No response

Activity

  1. schiller-manuel commented on Oct 12, 2024

    @schiller-manuel
    Collaborator

    Since setting state in componentDidCatch is deprecated, we cannot do much here, as getDerivedStateFromError does not expose errorInfo
    https://react.dev/reference/react/Component#componentdidcatch-caveats

    The best "solution" would probably be to remove errorInfo from ErrorComponentProps

  2. SeanCassiere commented on Oct 26, 2024

    @SeanCassiere
    Member

    Added this removal of errorInfo onto the v2 checklist.
    #975

    Closing this for now.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions