-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure default _app is used when falling back to default _error (#39467)
* Ensure default _app is used when falling back to default _error * make render check less specific due to arbitrary wait
- Loading branch information
Showing
6 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function App({ Component, pageProps }) { | ||
if (process.env.NODE_ENV === 'production' && typeof window !== 'undefined') { | ||
if (!window.renderAttempts) { | ||
window.renderAttempts = 0 | ||
} | ||
window.renderAttempts++ | ||
throw new Error('error in custom _app') | ||
} | ||
return ( | ||
<> | ||
<p id="custom-app">from _app</p> | ||
<Component {...pageProps} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default function Error() { | ||
if (process.env.NODE_ENV === 'production' && typeof window !== 'undefined') { | ||
throw new Error('error in custom _app') | ||
} | ||
return <div>Error encountered!</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>index page</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default function Error() { | ||
if (process.env.NODE_ENV === 'production' && typeof window !== 'undefined') { | ||
throw new Error('error in pages/with-error') | ||
} | ||
return <div>with-error</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { check, renderViaHTTP, waitFor } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
describe('fatal-render-errror', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: new FileRef(join(__dirname, 'app')), | ||
dependencies: {}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should render page without error correctly', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('index page') | ||
expect(html).toContain('from _app') | ||
}) | ||
|
||
it('should handle fatal error in _app and _error without loop on direct visit', async () => { | ||
const browser = await webdriver(next.url, '/with-error') | ||
|
||
// wait a bit to see if we are rendering multiple times unexpectedly | ||
await waitFor(500) | ||
expect(await browser.eval('window.renderAttempts')).toBeLessThan(10) | ||
|
||
const html = await browser.eval('document.documentElement.innerHTML') | ||
expect(html).not.toContain('from _app') | ||
expect(html).toContain( | ||
'Application error: a client-side exception has occurred' | ||
) | ||
}) | ||
|
||
it('should handle fatal error in _app and _error without loop on client-transition', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
await browser.eval('window.renderAttempts = 0') | ||
|
||
await browser.eval('window.next.router.push("/with-error")') | ||
await check(() => browser.eval('location.pathname'), '/with-error') | ||
|
||
// wait a bit to see if we are rendering multiple times unexpectedly | ||
await waitFor(500) | ||
expect(await browser.eval('window.renderAttempts')).toBeLessThan(10) | ||
|
||
const html = await browser.eval('document.documentElement.innerHTML') | ||
expect(html).not.toContain('from _app') | ||
expect(html).toContain( | ||
'Application error: a client-side exception has occurred' | ||
) | ||
}) | ||
}) |