提交 beed775e 编写于 作者: G Gerald Monaco 提交者: Tim Neutkens

Update legacy _app context (#9083)

上级 b6be95ba
...@@ -13,7 +13,7 @@ type SingletonRouterBase = { ...@@ -13,7 +13,7 @@ type SingletonRouterBase = {
ready(cb: () => any): void ready(cb: () => any): void
} }
export { Router, NextRouter } export { Router, RouterContext, NextRouter }
export type SingletonRouter = SingletonRouterBase & NextRouter export type SingletonRouter = SingletonRouterBase & NextRouter
......
import React from 'react' import React from 'react'
import PropTypes from 'prop-types'
import { NextComponentType, NextPageContext } from '../next-server/lib/utils' import { NextComponentType, NextPageContext } from '../next-server/lib/utils'
import { NextRouter } from './router' import { NextRouter, RouterContext } from './router'
export type WithRouterProps = { export type WithRouterProps = {
router: NextRouter router: NextRouter
...@@ -21,19 +20,12 @@ export default function withRouter< ...@@ -21,19 +20,12 @@ export default function withRouter<
class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> { class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> {
static displayName?: string static displayName?: string
static getInitialProps?: any static getInitialProps?: any
static contextTypes = { static contextType = RouterContext
router: PropTypes.object,
}
context!: WithRouterProps context!: React.ContextType<typeof RouterContext>
render() { render() {
return ( return <ComposedComponent router={this.context} {...this.props as any} />
<ComposedComponent
router={this.context.router}
{...this.props as any}
/>
)
} }
} }
......
import React, { ErrorInfo } from 'react' import React, { ErrorInfo } from 'react'
import PropTypes from 'prop-types'
import { import {
execOnce, execOnce,
loadGetInitialProps, loadGetInitialProps,
...@@ -7,7 +6,7 @@ import { ...@@ -7,7 +6,7 @@ import {
AppInitialProps, AppInitialProps,
AppPropsType, AppPropsType,
} from '../next-server/lib/utils' } from '../next-server/lib/utils'
import { Router, makePublicRouterInstance } from '../client/router' import { Router } from '../client/router'
export { AppInitialProps } export { AppInitialProps }
...@@ -31,18 +30,9 @@ export default class App<P = {}, CP = {}, S = {}> extends React.Component< ...@@ -31,18 +30,9 @@ export default class App<P = {}, CP = {}, S = {}> extends React.Component<
P & AppProps<CP>, P & AppProps<CP>,
S S
> { > {
static childContextTypes = {
router: PropTypes.object,
}
static origGetInitialProps = appGetInitialProps static origGetInitialProps = appGetInitialProps
static getInitialProps = appGetInitialProps static getInitialProps = appGetInitialProps
getChildContext() {
return {
router: makePublicRouterInstance(this.props.router),
}
}
// Kept here for backwards compatibility. // Kept here for backwards compatibility.
// When someone ended App they could call `super.componentDidCatch`. // When someone ended App they could call `super.componentDidCatch`.
// @deprecated This method is no longer needed. Errors are caught at the top level // @deprecated This method is no longer needed. Errors are caught at the top level
......
...@@ -9,6 +9,6 @@ const appDir = join(__dirname, '../react-site') ...@@ -9,6 +9,6 @@ const appDir = join(__dirname, '../react-site')
describe('Build Stats Output', () => { describe('Build Stats Output', () => {
it('Shows correct package count in output', async () => { it('Shows correct package count in output', async () => {
const { stdout } = await nextBuild(appDir, undefined, { stdout: true }) const { stdout } = await nextBuild(appDir, undefined, { stdout: true })
expect(stdout).toMatch(/\/something .*?5/) expect(stdout).toMatch(/\/something .*?4/)
}) })
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册