Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay hydration until after page is visible in development
- Loading branch information
Showing
5 changed files
with
93 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
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,31 @@ | ||
import React from 'react' | ||
|
||
class App extends React.Component { | ||
constructor() { | ||
super() | ||
|
||
this.divRef = React.createRef() | ||
|
||
this.state = { | ||
refHeight: 0, | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
const refHeight = this.divRef.current.clientHeight | ||
this.setState({ refHeight }) | ||
} | ||
|
||
render() { | ||
const { refHeight } = this.state | ||
|
||
return ( | ||
<div ref={this.divRef}> | ||
<h1>DOM Ref test using 9.2.0</h1> | ||
<code id="ref-val">{`this component is ${refHeight}px tall`}</code> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default App |
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,48 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import path from 'path' | ||
import webdriver from 'next-webdriver' | ||
import { | ||
nextBuild, | ||
nextStart, | ||
launchApp, | ||
findPort, | ||
waitFor, | ||
killApp, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 | ||
const appDir = path.join(__dirname, '..') | ||
let app | ||
let appPort | ||
|
||
const runTest = () => { | ||
it('Has correct initial ref values', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
await waitFor(2000) | ||
expect(await browser.elementByCss('#ref-val').text()).toContain('76px') | ||
}) | ||
} | ||
|
||
describe('Hydration', () => { | ||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTest() | ||
}) | ||
|
||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTest() | ||
}) | ||
}) |