Skip to content

ErrorBoundary fallback has inconsistent typing #3828

@jcomo

Description

@jcomo

Core or SDK?

Platform/SDK

Which part? Which one?

Javascript / React

Description

The fallback prop of the ErrorBoundary accepts a React.ReactNode (or function that returns one), but the body of the render method checks for isValidElement (see:

if (React.isValidElement(fallback)) {
return fallback;
}
)

The docs suggest that a string (ReactNode) can be passed in, but the ErrorBoundary will render null.

Note that if you supply a function for fallback that returns a ReactNode (eg. string), it will actually render because there is no check for isValidElement around the fallback function variant.

Suggested Solution

The solution depends on the preference.

Personally, I think it should be an element. If that's the consensus, we should update the typings in sentry-javascript and the docs to reflect that.

If it should be a ReactNode, then we need to remove the isValidElement check.

Happy to implement either solution! Either way, we should include a new test for this in sentry-javascript.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions