Commit 9532cc12 authored by Michael Fix's avatar Michael Fix Committed by Tim Neutkens

Remove old UNSAFE_ lifecycle methods (#5020)

~I am not sure if this is a valid fix yet, but I was going to let CI run the tests for me. I'll close and look into it if the build fails.~

Let me know if this will cause issues, but I don't think it should. The React docs recommends moving `componentWillMount` logic into the constructor
parent 4c6ec18d
import React, { Component } from 'react' import React, { Component } from 'react'
import {polyfill} from 'react-lifecycles-compat'
import { getDisplayName } from './utils' import { getDisplayName } from './utils'
export default function withSideEffect (reduceComponentsToState, handleStateChangeOnClient, mapStateOnServer) { export default function withSideEffect (reduceComponentsToState, handleStateChangeOnClient, mapStateOnServer) {
...@@ -57,18 +56,18 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan ...@@ -57,18 +56,18 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
return recordedState return recordedState
} }
componentDidUpdate () { constructor (props) {
super(props)
mountedInstances.add(this)
emitChange(this) emitChange(this)
} }
componentWillUnmount () { componentDidUpdate () {
mountedInstances.delete(this)
emitChange(this) emitChange(this)
} }
// eslint-disable-next-line camelcase componentWillUnmount () {
UNSAFE_componentWillMount () { mountedInstances.delete(this)
mountedInstances.add(this)
emitChange(this) emitChange(this)
} }
...@@ -77,9 +76,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan ...@@ -77,9 +76,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
} }
} }
// Make UNSAFE_ compatible with version of React under 16.3
polyfill(SideEffect)
return SideEffect return SideEffect
} }
} }
...@@ -96,7 +96,6 @@ ...@@ -96,7 +96,6 @@
"prop-types": "15.6.0", "prop-types": "15.6.0",
"prop-types-exact": "1.1.1", "prop-types-exact": "1.1.1",
"react-error-overlay": "4.0.0", "react-error-overlay": "4.0.0",
"react-lifecycles-compat": "3.0.4",
"react-loadable": "5.4.0", "react-loadable": "5.4.0",
"recursive-copy": "2.0.6", "recursive-copy": "2.0.6",
"resolve": "1.5.0", "resolve": "1.5.0",
......
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
export default (props) => <div id='head-1'>
<Head>
<meta
name='description'
content='Head One'
/>
</Head>
<Link href='/nav/head-2'>
<a id='to-head-2'>to head 2</a>
</Link>
</div>
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
export default (props) => <div id='head-2'>
<Head>
<meta
name='description'
content='Head Two'
/>
</Head>
<Link href='/nav/head-1'>
<a id='to-head-1'>to head 1</a>
</Link>
</div>
...@@ -692,5 +692,23 @@ export default (context, render) => { ...@@ -692,5 +692,23 @@ export default (context, render) => {
browser.close() browser.close()
}) })
}) })
describe('updating head while client routing', () => {
it('should update head during client routing', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/nav/head-1')
expect(await browser.elementByCss('meta[name="description"]').getAttribute('content')).toBe('Head One')
await browser.elementByCss('#to-head-2').click().waitForElementByCss('#head-2')
expect(await browser.elementByCss('meta[name="description"]').getAttribute('content')).toBe('Head Two')
await browser.elementByCss('#to-head-1').click().waitForElementByCss('#head-1')
expect(await browser.elementByCss('meta[name="description"]').getAttribute('content')).toBe('Head One')
} finally {
if (browser) {
browser.close()
}
}
})
})
}) })
} }
...@@ -6481,10 +6481,6 @@ react-error-overlay@4.0.0: ...@@ -6481,10 +6481,6 @@ react-error-overlay@4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4" resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"
react-lifecycles-compat@3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
react-loadable@5.4.0: react-loadable@5.4.0:
version "5.4.0" version "5.4.0"
resolved "https://registry.yarnpkg.com/react-loadable/-/react-loadable-5.4.0.tgz#3b6b7d51121a7868fd155be848a36e02084742c9" resolved "https://registry.yarnpkg.com/react-loadable/-/react-loadable-5.4.0.tgz#3b6b7d51121a7868fd155be848a36e02084742c9"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment