Skip to content

Commit

Permalink
Update legacy _app context
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll committed Oct 15, 2019
1 parent 8676b0f commit dc89d24
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/next/client/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type SingletonRouterBase = {
ready(cb: () => any): void
}

export { Router, NextRouter }
export { Router, RouterContext, NextRouter }

export type SingletonRouter = SingletonRouterBase & NextRouter

Expand Down
16 changes: 4 additions & 12 deletions packages/next/client/with-router.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,19 +20,12 @@ export default function withRouter<
class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> {
static displayName?: string
static getInitialProps?: any
static contextTypes = {
router: PropTypes.object,
}
static contextType = RouterContext

context!: WithRouterProps
context!: React.ContextType<typeof RouterContext>

render() {
return (
<ComposedComponent
router={this.context.router}
{...this.props as any}
/>
)
return <ComposedComponent router={this.context} {...this.props as any} />
}
}

Expand Down
12 changes: 1 addition & 11 deletions packages/next/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { ErrorInfo } from 'react'
import PropTypes from 'prop-types'
import {
execOnce,
loadGetInitialProps,
AppContextType,
AppInitialProps,
AppPropsType,
} from '../next-server/lib/utils'
import { Router, makePublicRouterInstance } from '../client/router'
import { Router } from '../client/router'

export { AppInitialProps }

Expand All @@ -31,18 +30,9 @@ export default class App<P = {}, CP = {}, S = {}> extends React.Component<
P & AppProps<CP>,
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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/build-stats-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

0 comments on commit dc89d24

Please sign in to comment.