mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Remove _containerProps context (#5327)
This PR removes the obsolete `_containerProps` context.
This commit is contained in:
parent
30924ea1be
commit
df41997d50
|
@ -30,8 +30,7 @@ const {
|
|||
assetPrefix,
|
||||
runtimeConfig,
|
||||
dynamicIds
|
||||
},
|
||||
location
|
||||
}
|
||||
} = window
|
||||
|
||||
const prefix = assetPrefix || ''
|
||||
|
@ -102,12 +101,11 @@ export default async ({
|
|||
err: initialErr
|
||||
})
|
||||
|
||||
router.subscribe(({ App, Component, props, hash, err }) => {
|
||||
render({ App, Component, props, err, hash, emitter })
|
||||
router.subscribe(({ App, Component, props, err }) => {
|
||||
render({ App, Component, props, err, emitter })
|
||||
})
|
||||
|
||||
const hash = location.hash.substring(1)
|
||||
render({ App, Component, props, hash, err: initialErr, emitter })
|
||||
render({ App, Component, props, err: initialErr, emitter })
|
||||
|
||||
return emitter
|
||||
}
|
||||
|
@ -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
|
||||
// this is for when ErrorComponent gets replaced by Component by HMR
|
||||
if (!props && Component &&
|
||||
|
@ -172,7 +170,7 @@ async function doRender ({ App, Component, props, hash, err, emitter: emitterPro
|
|||
Component = Component || lastAppProps.Component
|
||||
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 = appProps
|
||||
|
||||
|
|
19
lib/app.js
19
lib/app.js
|
@ -1,18 +1,14 @@
|
|||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import shallowEquals from './shallow-equals'
|
||||
import { execOnce, loadGetInitialProps } from './utils'
|
||||
import { makePublicRouterInstance } from './router'
|
||||
|
||||
export default class App extends Component {
|
||||
static childContextTypes = {
|
||||
_containerProps: PropTypes.any,
|
||||
headManager: PropTypes.object,
|
||||
router: PropTypes.object
|
||||
}
|
||||
|
||||
static displayName = 'App'
|
||||
|
||||
static async getInitialProps ({ Component, router, ctx }) {
|
||||
const pageProps = await loadGetInitialProps(Component, ctx)
|
||||
return {pageProps}
|
||||
|
@ -22,8 +18,7 @@ export default class App extends Component {
|
|||
const { headManager } = this.props
|
||||
return {
|
||||
headManager,
|
||||
router: makePublicRouterInstance(this.props.router),
|
||||
_containerProps: {...this.props}
|
||||
router: makePublicRouterInstance(this.props.router)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,25 +38,17 @@ export default class App extends Component {
|
|||
}
|
||||
|
||||
export class Container extends Component {
|
||||
static contextTypes = {
|
||||
_containerProps: PropTypes.any
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.scrollToHash()
|
||||
}
|
||||
|
||||
shouldComponentUpdate (nextProps) {
|
||||
// need this check not to rerender component which has already thrown an error
|
||||
return !shallowEquals(this.props, nextProps)
|
||||
}
|
||||
|
||||
componentDidUpdate () {
|
||||
this.scrollToHash()
|
||||
}
|
||||
|
||||
scrollToHash () {
|
||||
const { hash } = this.context._containerProps
|
||||
let { hash } = window.location
|
||||
hash = hash ? hash.substring(1) : false
|
||||
if (!hash) return
|
||||
|
||||
const el = document.getElementById(hash)
|
||||
|
|
Loading…
Reference in a new issue