react icon indicating copy to clipboard operation
react copied to clipboard

Set the current fiber to the source of the error during error reporting

Open sebmarkbage opened this issue 1 month ago • 2 comments

Stacked on #29038.

This lets us expose the component stack to the error reporting that happens here as console.error patching. Now if you just call console.error in the error handlers it'll get the component stack added to the end by React DevTools.

However, unfortunately this happens a little too late so the Fiber will be disconnected with its .return pointer set to null already. So it'll be too late to extract a parent component stack from but you can at least get the stack from source to error boundary. To work around this I manually add the parent component stack in our default handlers when owner stacks are off. We could potentially fix this but you can also just include it yourself if you're calling console.error and it's not a problem for owner stacks.

This is not a problem for owner stacks because we'll still have those and so for those just calling console.error just works. However, the main feature is that by letting React add them, we can switch to using native error stacks when available.

sebmarkbage avatar May 10 '24 19:05 sebmarkbage