roact
roact copied to clipboard
Error boundaries!
Adds error boundaries like React's newer version of them. An error boundary is any component that declares a method with the signature static getDerivedStateFromError(message: string) -> setStateMapper. If this method is declared, the component will capture any errors from its children, pass the message to getDerivedStateFromError, apply the resulting state delta, then re-try the render.
The boundary will re-try the render only once; if the re-tried render throws, that error will propagate upwards until it either surfaces or hits another error boundary. It is the responsibility of the error boundary component to make sure this doesn't happen. If the re-render succeeds, the normal lifecycle process (calling either didMount or didUpdate depending on which is appropriate) will continue.
Questions I'm not sure about:
- Is this actually safe, or does this secretly corrupt some state that causes problems later?
- Should
getDerivedStateFromErrorbe allowed to return a mapper function, or should it only be allowed to return a dictionary? Allowing a function to be returned gives the function, indirectly, access to the component's state and props tables.
Checklist before submitting:
- [x] Added/updated relevant tests