Files
4b538e9879 Add error link when hydration error occurs (#31519)
This adds an error document/link for hydration errors to help users debug these easier. While looking at adding this also noticed a typo in the dev-overlay which is fixed. 

<details>

<summary>screenshot</summary>

<img width="1109" alt="Screen Shot 2021-11-16 at 15 56 29" src="https://user-images.githubusercontent.com/22380829/142078200-6c036ed9-ca7f-4d26-ae07-eb9bd89e991a.png">

</details>

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tim Neutkens <[email protected]>
2021-11-23 13:10:56 +00:00

29 lines
725 B
JavaScript

import { useRouter } from 'next/router'
if (typeof window !== 'undefined') {
window.caughtWarns = []
const origWarn = window.console.warn
const origError = window.console.error
window.console.warn = function (...args) {
window.caughtWarns.push(args)
origWarn(...args)
}
window.console.error = function (...args) {
window.caughtWarns.push(args)
origError(...args)
}
window.pathnames = []
}
export default function Page() {
if (typeof window !== 'undefined') {
window.pathnames.push(window.location.pathname)
if (window.location.pathname.includes('hydrate-error')) {
return <p>hydration error</p>
}
}
// eslint-disable-next-line
return <p>{useRouter().asPath}</p>
}