diff --git a/client/index.js b/client/index.js index c8d0eef6..4f7b83b9 100644 --- a/client/index.js +++ b/client/index.js @@ -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 diff --git a/lib/app.js b/lib/app.js index 80899ab0..8d1df776 100644 --- a/lib/app.js +++ b/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)