Commit df41997d authored by Henrik Wenz's avatar Henrik Wenz Committed by Tim Neutkens

Remove _containerProps context (#5327)

This PR removes the obsolete `_containerProps` context.
parent 30924ea1
...@@ -30,8 +30,7 @@ const { ...@@ -30,8 +30,7 @@ const {
assetPrefix, assetPrefix,
runtimeConfig, runtimeConfig,
dynamicIds dynamicIds
}, }
location
} = window } = window
const prefix = assetPrefix || '' const prefix = assetPrefix || ''
...@@ -102,12 +101,11 @@ export default async ({ ...@@ -102,12 +101,11 @@ export default async ({
err: initialErr err: initialErr
}) })
router.subscribe(({ App, Component, props, hash, err }) => { router.subscribe(({ App, Component, props, err }) => {
render({ App, Component, props, err, hash, emitter }) render({ App, Component, props, err, emitter })
}) })
const hash = location.hash.substring(1) render({ App, Component, props, err: initialErr, emitter })
render({ App, Component, props, hash, err: initialErr, emitter })
return emitter return emitter
} }
...@@ -159,7 +157,7 @@ function renderReactElement (reactEl, domEl) { ...@@ -159,7 +157,7 @@ function renderReactElement (reactEl, domEl) {
} }
} }
async function doRender ({ App, Component, props, hash, err, emitter: emitterProp = emitter }) { async function doRender ({ App, Component, props, err, emitter: emitterProp = emitter }) {
// Usual getInitialProps fetching is handled in next/router // Usual getInitialProps fetching is handled in next/router
// this is for when ErrorComponent gets replaced by Component by HMR // this is for when ErrorComponent gets replaced by Component by HMR
if (!props && Component && if (!props && Component &&
...@@ -172,7 +170,7 @@ async function doRender ({ App, Component, props, hash, err, emitter: emitterPro ...@@ -172,7 +170,7 @@ async function doRender ({ App, Component, props, hash, err, emitter: emitterPro
Component = Component || lastAppProps.Component Component = Component || lastAppProps.Component
props = props || lastAppProps.props props = props || lastAppProps.props
const appProps = { Component, hash, err, router, headManager, ...props } const appProps = { Component, err, router, headManager, ...props }
// lastAppProps has to be set before ReactDom.render to account for ReactDom throwing an error. // lastAppProps has to be set before ReactDom.render to account for ReactDom throwing an error.
lastAppProps = appProps lastAppProps = appProps
......
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import shallowEquals from './shallow-equals'
import { execOnce, loadGetInitialProps } from './utils' import { execOnce, loadGetInitialProps } from './utils'
import { makePublicRouterInstance } from './router' import { makePublicRouterInstance } from './router'
export default class App extends Component { export default class App extends Component {
static childContextTypes = { static childContextTypes = {
_containerProps: PropTypes.any,
headManager: PropTypes.object, headManager: PropTypes.object,
router: PropTypes.object router: PropTypes.object
} }
static displayName = 'App'
static async getInitialProps ({ Component, router, ctx }) { static async getInitialProps ({ Component, router, ctx }) {
const pageProps = await loadGetInitialProps(Component, ctx) const pageProps = await loadGetInitialProps(Component, ctx)
return {pageProps} return {pageProps}
...@@ -22,8 +18,7 @@ export default class App extends Component { ...@@ -22,8 +18,7 @@ export default class App extends Component {
const { headManager } = this.props const { headManager } = this.props
return { return {
headManager, headManager,
router: makePublicRouterInstance(this.props.router), router: makePublicRouterInstance(this.props.router)
_containerProps: {...this.props}
} }
} }
...@@ -43,25 +38,17 @@ export default class App extends Component { ...@@ -43,25 +38,17 @@ export default class App extends Component {
} }
export class Container extends Component { export class Container extends Component {
static contextTypes = {
_containerProps: PropTypes.any
}
componentDidMount () { componentDidMount () {
this.scrollToHash() this.scrollToHash()
} }
shouldComponentUpdate (nextProps) {
// need this check not to rerender component which has already thrown an error
return !shallowEquals(this.props, nextProps)
}
componentDidUpdate () { componentDidUpdate () {
this.scrollToHash() this.scrollToHash()
} }
scrollToHash () { scrollToHash () {
const { hash } = this.context._containerProps let { hash } = window.location
hash = hash ? hash.substring(1) : false
if (!hash) return if (!hash) return
const el = document.getElementById(hash) const el = document.getElementById(hash)
......
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