Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error boundary doesn't catch subsequent errors #1570

Closed
dwelle opened this issue Apr 24, 2019 · 0 comments · Fixed by #1572
Closed

Error boundary doesn't catch subsequent errors #1570

dwelle opened this issue Apr 24, 2019 · 0 comments · Fixed by #1572

Comments

@dwelle
Copy link

dwelle commented Apr 24, 2019

When a child component rendered from a loop throws, subsequent errors are not caught by the error boundary.

Sandbox here

preact ^10.0.0-beta.0:

import { render, h, Component } from "preact";

let throws = 0;
const Child = () => {
    console.log(`child throwing (${++throws})`);
    throw new Error("oi!");
};

class TopErrorBoundary extends Component {
    state = { error: false }
    __renders = 0;

    static getDerivedStateFromError (error, info) {
        console.log(`getDerivedStateFromError called`);
        return { error: true };
    }

    render () {
        console.log(`TopErrorBoundary render()`, this.state);
        return this.state.error
            ? <h1>Something went wrong.</h1>
            : this.props.children;
    }
}

render(
    <TopErrorBoundary>
        <div>
            {/* CHANGE THIS ARRAY TO LENGTH: 1 FOR THE ERROR BOUNDARY TO WORK */}
            {[1, 2].map(() => {
                return <Child />;
            })}
        </div>
    </TopErrorBoundary>,
    document.body
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant