fix(error handling): try reloading the app when encountering a javascript error (#3435)

This commit is contained in:
Moody Salem 2022-03-31 16:39:31 -04:00 committed by GitHub
parent c0bdb8db12
commit 5cf9e84db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,6 +49,11 @@ type ErrorBoundaryState = {
const IS_UNISWAP = window.location.hostname === 'app.uniswap.org'
async function updateServiceWorker(): Promise<void> {
const ready = await navigator.serviceWorker.ready
await ready.update()
}
export default class ErrorBoundary extends React.Component<unknown, ErrorBoundaryState> {
constructor(props: unknown) {
super(props)
@ -56,6 +61,13 @@ export default class ErrorBoundary extends React.Component<unknown, ErrorBoundar
}
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
updateServiceWorker()
.then(() => {
window.location.reload()
})
.catch((error) => {
console.error('Failed to update service worker', error)
})
return { error }
}