Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7e7be0e2
Commit
7e7be0e2
authored
Jan 14, 2019
by
Alexander Nanberg
Committed by
Tim Neutkens
Jan 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert #6030 (#6052)
* Revert #6030 * Fix _app childContextTypes
parent
189ac8bb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
40 deletions
+40
-40
router.js
packages/next-server/lib/router/router.js
+0
-3
render.tsx
packages/next-server/server/render.tsx
+6
-8
index.js
packages/next/client/index.js
+7
-11
router.js
packages/next/client/router.js
+0
-3
with-router.js
packages/next/client/with-router.js
+15
-15
_app.js
packages/next/pages/_app.js
+12
-0
No files found.
packages/next-server/lib/router/router.js
View file @
7e7be0e2
/* global __NEXT_DATA__ */
import
React
from
'react'
import
{
parse
,
format
}
from
'url'
import
mitt
from
'../mitt'
import
shallowEquals
from
'./shallow-equals'
import
{
loadGetInitialProps
,
getURL
}
from
'../utils'
export
const
RouterContext
=
React
.
createContext
()
export
default
class
Router
{
static
events
=
mitt
()
...
...
packages/next-server/server/render.tsx
View file @
7e7be0e2
...
...
@@ -2,7 +2,7 @@ import {IncomingMessage, ServerResponse} from 'http'
import
{
ParsedUrlQuery
}
from
'querystring'
import
React
from
'react'
import
{
renderToString
,
renderToStaticMarkup
}
from
'react-dom/server'
import
Router
,
{
RouterContext
}
from
'../lib/router/router'
import
Router
from
'../lib/router/router'
import
{
loadGetInitialProps
,
isResSent
}
from
'../lib/utils'
import
Head
,
{
defaultHead
}
from
'../lib/head'
import
Loadable
from
'../lib/loadable'
...
...
@@ -169,13 +169,11 @@ export async function renderToHTML (req: IncomingMessage, res: ServerResponse, p
return
render
(
renderElementToString
,
<
LoadableCapture
report=
{
(
moduleName
)
=>
reactLoadableModules
.
push
(
moduleName
)
}
>
<
RouterContext
.
Provider
value=
{
router
}
>
<
EnhancedApp
Component=
{
EnhancedComponent
}
router=
{
router
}
{
...
props
}
/>
</
RouterContext
.
Provider
>
<
EnhancedApp
Component=
{
EnhancedComponent
}
router=
{
router
}
{
...
props
}
/>
</
LoadableCapture
>
)
}
...
...
packages/next/client/index.js
View file @
7e7be0e2
import
React
from
'react'
import
ReactDOM
from
'react-dom'
import
HeadManager
from
'./head-manager'
import
{
createRouter
,
makePublicRouterInstance
,
RouterContext
}
from
'next/router'
import
{
createRouter
}
from
'next/router'
import
mitt
from
'next-server/dist/lib/mitt'
import
{
loadGetInitialProps
,
getURL
}
from
'next-server/dist/lib/utils'
import
PageLoader
from
'./page-loader'
...
...
@@ -181,11 +181,9 @@ async function doRender ({ App, Component, props, err, emitter: emitterProp = em
// In development runtime errors are caught by react-error-overlay.
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
renderReactElement
((
<
RouterContext
.
Provider
value
=
{
makePublicRouterInstance
(
router
)}
>
<
HeadManagerContext
.
Provider
value
=
{
headManager
}
>
<
App
{...
appProps
}
/
>
<
/HeadManagerContext.Provider
>
<
/RouterContext.Provider
>
<
HeadManagerContext
.
Provider
value
=
{
headManager
}
>
<
App
{...
appProps
}
/
>
<
/HeadManagerContext.Provider
>
),
appContainer
)
}
else
{
// In production we catch runtime errors using componentDidCatch which will trigger renderError.
...
...
@@ -198,11 +196,9 @@ async function doRender ({ App, Component, props, err, emitter: emitterProp = em
}
renderReactElement
((
<
ErrorBoundary
onError
=
{
onError
}
>
<
RouterContext
.
Provider
value
=
{
makePublicRouterInstance
(
router
)}
>
<
HeadManagerContext
.
Provider
value
=
{
headManager
}
>
<
App
{...
appProps
}
/
>
<
/HeadManagerContext.Provider
>
<
/RouterContext.Provider
>
<
HeadManagerContext
.
Provider
value
=
{
headManager
}
>
<
App
{...
appProps
}
/
>
<
/HeadManagerContext.Provider
>
<
/ErrorBoundary
>
),
appContainer
)
}
...
...
packages/next/client/router.js
View file @
7e7be0e2
...
...
@@ -75,9 +75,6 @@ export default SingletonRouter
// Reexport the withRoute HOC
export
{
default
as
withRouter
}
from
'./with-router'
// Export RouterContext
export
{
RouterContext
}
from
'next-server/dist/lib/router/router'
// INTERNAL APIS
// -------------
// (do not use following exports inside the app)
...
...
packages/next/client/with-router.js
View file @
7e7be0e2
import
React
from
'react'
import
React
,
{
Component
}
from
'react'
import
PropTypes
from
'prop-types'
import
hoistStatics
from
'hoist-non-react-statics'
import
{
getDisplayName
}
from
'next-server/dist/lib/utils'
import
{
RouterContext
}
from
'./router'
export
default
function
withRouter
(
ComposedComponent
)
{
const
displayName
=
getDisplayName
(
ComposedComponent
)
function
WithRouteWrapper
(
props
)
{
return
(
<
RouterContext
.
Consumer
>
{
router
=>
(
<
ComposedComponent
router
=
{
router
}
{...
props
}
/
>
)}
<
/RouterContext.Consumer
>
)
}
class
WithRouteWrapper
extends
Component
{
static
contextTypes
=
{
router
:
PropTypes
.
object
}
static
displayName
=
`withRouter(
${
displayName
}
)`
WithRouteWrapper
.
displayName
=
`withRouter(
${
displayName
}
)`
render
()
{
return
<
ComposedComponent
router
=
{
this
.
context
.
router
}
{...
this
.
props
}
/
>
}
}
return
hoistStatics
(
WithRouteWrapper
,
ComposedComponent
)
}
packages/next/pages/_app.js
View file @
7e7be0e2
import
React
,
{
Component
}
from
'react'
import
PropTypes
from
'prop-types'
import
{
execOnce
,
loadGetInitialProps
}
from
'next-server/dist/lib/utils'
import
{
makePublicRouterInstance
}
from
'next/router'
export
default
class
App
extends
Component
{
static
childContextTypes
=
{
router
:
PropTypes
.
object
}
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
const
pageProps
=
await
loadGetInitialProps
(
Component
,
ctx
)
return
{
pageProps
}
}
getChildContext
()
{
return
{
router
:
makePublicRouterInstance
(
this
.
props
.
router
)
}
}
// Kept here for backwards compatibility.
// When someone ended App they could call `super.componentDidCatch`. This is now deprecated.
componentDidCatch
(
err
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment