Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hydration with custom _app and granular chunks (#10144)
* Add failing hydration test * Add importing of next/router to _app * Fix type * Update _app check for windows * Remove babel fix * Update to use webpack to require next/router
- Loading branch information
Showing
7 changed files
with
72 additions
and
2 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
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 @@ | ||
export default ({ Component, pageProps }) => <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,16 @@ | ||
import Document, { Head, Html, Main, NextScript } from 'next/document' | ||
import React from 'react' | ||
|
||
class WeddingDocument extends Document { | ||
render() { | ||
return ( | ||
<Html lang="en-GB"> | ||
<Head /> | ||
<Main /> | ||
<NextScript /> | ||
</Html> | ||
) | ||
} | ||
} | ||
|
||
export default WeddingDocument |
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 () => { | ||
if (typeof window !== 'undefined') { | ||
window.didHydrate = true | ||
} | ||
return 'details' | ||
} |
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 () => { | ||
if (typeof window !== 'undefined') { | ||
window.didHydrate = true | ||
} | ||
return 'index' | ||
} |
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,33 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import path from 'path' | ||
import fs from 'fs-extra' | ||
import webdriver from 'next-webdriver' | ||
import { | ||
nextBuild, | ||
nextStart, | ||
findPort, | ||
waitFor, | ||
killApp, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 | ||
const appDir = path.join(__dirname, '..') | ||
let app | ||
let appPort | ||
|
||
describe('Hydration', () => { | ||
beforeAll(async () => { | ||
await fs.remove(path.join(appDir, '.next')) | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
it('Hydrates correctly', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
await waitFor(2000) | ||
expect(await browser.eval('window.didHydrate')).toBe(true) | ||
}) | ||
}) |