Handle React hydration errors #8889
Labels
cross-team
For visibility for both World Service teams (Engage & Media)
Refinement Needed
This is ready for refinement. It shouldn't be worked on until it has been refined by Dev & Test.
technical-work
Technical debt, support work and building new technical tools and features
Is your feature request related to a problem? Please describe.
Errors that happen on the client in the React app hydration phase are currently unhandled. The result of this is a white screen shown to the user and a hard to trace error logged in the console.
Describe the solution you'd like
Instead of a white screen shown to the user we should show a localised error message. We should also log the error message and a stack trace in the console. Ideally we should log this using Winston so we can be alerted to errors sooner than noticing unusual patterns in traffic, however Winston is not currently setup to work on the client.
An error-boundary component can be used to wrap the ClientApp component but we also need to try/catch the hydration function and log any errors from this function before the error-boundary component takes effect because from experience these errors were more helpful than what was logged from error-boundary component.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
NB
NextJS handle similar errors with an error-boundary component that uses componentDidCatch as shown here which is their function that calls
ReactDOM.hydrate
Testing notes
[Tester to complete]
Dev insight: Will Cypress tests be required or are unit tests sufficient? Will there be any potential regression? etc
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: