diff --git a/packages/next/client/router.ts b/packages/next/client/router.ts index 32da8433124f4c614828b376ad63de7d35b0e168..ad8af87bcf663f098aa32c7ad8786622170965a7 100644 --- a/packages/next/client/router.ts +++ b/packages/next/client/router.ts @@ -13,7 +13,7 @@ type SingletonRouterBase = { ready(cb: () => any): void } -export { Router, NextRouter } +export { Router, RouterContext, NextRouter } export type SingletonRouter = SingletonRouterBase & NextRouter diff --git a/packages/next/client/with-router.tsx b/packages/next/client/with-router.tsx index 080d167104d230db49e6cd3b03176ad4b7cd762a..968d3ecdccfbe18593dd3bf2c63b4c4ce587fe62 100644 --- a/packages/next/client/with-router.tsx +++ b/packages/next/client/with-router.tsx @@ -1,7 +1,6 @@ import React from 'react' -import PropTypes from 'prop-types' import { NextComponentType, NextPageContext } from '../next-server/lib/utils' -import { NextRouter } from './router' +import { NextRouter, RouterContext } from './router' export type WithRouterProps = { router: NextRouter @@ -21,19 +20,12 @@ export default function withRouter< class WithRouteWrapper extends React.Component> { static displayName?: string static getInitialProps?: any - static contextTypes = { - router: PropTypes.object, - } + static contextType = RouterContext - context!: WithRouterProps + context!: React.ContextType render() { - return ( - - ) + return } } diff --git a/packages/next/pages/_app.tsx b/packages/next/pages/_app.tsx index 38143839f139860105901fbb72372ea5079a89c1..3971441a24339efd818473fbef94db0aa7f1061b 100644 --- a/packages/next/pages/_app.tsx +++ b/packages/next/pages/_app.tsx @@ -1,5 +1,4 @@ import React, { ErrorInfo } from 'react' -import PropTypes from 'prop-types' import { execOnce, loadGetInitialProps, @@ -7,7 +6,7 @@ import { AppInitialProps, AppPropsType, } from '../next-server/lib/utils' -import { Router, makePublicRouterInstance } from '../client/router' +import { Router } from '../client/router' export { AppInitialProps } @@ -31,18 +30,9 @@ export default class App

extends React.Component< P & AppProps, S > { - static childContextTypes = { - router: PropTypes.object, - } static origGetInitialProps = appGetInitialProps static getInitialProps = appGetInitialProps - getChildContext() { - return { - router: makePublicRouterInstance(this.props.router), - } - } - // Kept here for backwards compatibility. // When someone ended App they could call `super.componentDidCatch`. // @deprecated This method is no longer needed. Errors are caught at the top level diff --git a/test/integration/build-stats-output/test/index.test.js b/test/integration/build-stats-output/test/index.test.js index 094b473ca9dd56e760254a9cef976ea76479bfd1..3516e9a3947605bf74dc7d543079c523a16006e9 100644 --- a/test/integration/build-stats-output/test/index.test.js +++ b/test/integration/build-stats-output/test/index.test.js @@ -9,6 +9,6 @@ const appDir = join(__dirname, '../react-site') describe('Build Stats Output', () => { it('Shows correct package count in output', async () => { const { stdout } = await nextBuild(appDir, undefined, { stdout: true }) - expect(stdout).toMatch(/\/something .*?5/) + expect(stdout).toMatch(/\/something .*?4/) }) })