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
df41997d
Commit
df41997d
authored
Sep 29, 2018
by
Henrik Wenz
Committed by
Tim Neutkens
Sep 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove _containerProps context (#5327)
This PR removes the obsolete `_containerProps` context.
parent
30924ea1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
24 deletions
+9
-24
index.js
client/index.js
+6
-8
app.js
lib/app.js
+3
-16
No files found.
client/index.js
View file @
df41997d
...
@@ -30,8 +30,7 @@ const {
...
@@ -30,8 +30,7 @@ const {
assetPrefix
,
assetPrefix
,
runtimeConfig
,
runtimeConfig
,
dynamicIds
dynamicIds
},
}
location
}
=
window
}
=
window
const
prefix
=
assetPrefix
||
''
const
prefix
=
assetPrefix
||
''
...
@@ -102,12 +101,11 @@ export default async ({
...
@@ -102,12 +101,11 @@ export default async ({
err
:
initialErr
err
:
initialErr
})
})
router
.
subscribe
(({
App
,
Component
,
props
,
hash
,
err
})
=>
{
router
.
subscribe
(({
App
,
Component
,
props
,
err
})
=>
{
render
({
App
,
Component
,
props
,
err
,
hash
,
emitter
})
render
({
App
,
Component
,
props
,
err
,
emitter
})
})
})
const
hash
=
location
.
hash
.
substring
(
1
)
render
({
App
,
Component
,
props
,
err
:
initialErr
,
emitter
})
render
({
App
,
Component
,
props
,
hash
,
err
:
initialErr
,
emitter
})
return
emitter
return
emitter
}
}
...
@@ -159,7 +157,7 @@ function renderReactElement (reactEl, domEl) {
...
@@ -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
// Usual getInitialProps fetching is handled in next/router
// this is for when ErrorComponent gets replaced by Component by HMR
// this is for when ErrorComponent gets replaced by Component by HMR
if
(
!
props
&&
Component
&&
if
(
!
props
&&
Component
&&
...
@@ -172,7 +170,7 @@ async function doRender ({ App, Component, props, hash, err, emitter: emitterPro
...
@@ -172,7 +170,7 @@ async function doRender ({ App, Component, props, hash, err, emitter: emitterPro
Component
=
Component
||
lastAppProps
.
Component
Component
=
Component
||
lastAppProps
.
Component
props
=
props
||
lastAppProps
.
props
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 has to be set before ReactDom.render to account for ReactDom throwing an error.
lastAppProps
=
appProps
lastAppProps
=
appProps
...
...
lib/app.js
View file @
df41997d
import
React
,
{
Component
}
from
'react'
import
React
,
{
Component
}
from
'react'
import
PropTypes
from
'prop-types'
import
PropTypes
from
'prop-types'
import
shallowEquals
from
'./shallow-equals'
import
{
execOnce
,
loadGetInitialProps
}
from
'./utils'
import
{
execOnce
,
loadGetInitialProps
}
from
'./utils'
import
{
makePublicRouterInstance
}
from
'./router'
import
{
makePublicRouterInstance
}
from
'./router'
export
default
class
App
extends
Component
{
export
default
class
App
extends
Component
{
static
childContextTypes
=
{
static
childContextTypes
=
{
_containerProps
:
PropTypes
.
any
,
headManager
:
PropTypes
.
object
,
headManager
:
PropTypes
.
object
,
router
:
PropTypes
.
object
router
:
PropTypes
.
object
}
}
static
displayName
=
'App'
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
const
pageProps
=
await
loadGetInitialProps
(
Component
,
ctx
)
const
pageProps
=
await
loadGetInitialProps
(
Component
,
ctx
)
return
{
pageProps
}
return
{
pageProps
}
...
@@ -22,8 +18,7 @@ export default class App extends Component {
...
@@ -22,8 +18,7 @@ export default class App extends Component {
const
{
headManager
}
=
this
.
props
const
{
headManager
}
=
this
.
props
return
{
return
{
headManager
,
headManager
,
router
:
makePublicRouterInstance
(
this
.
props
.
router
),
router
:
makePublicRouterInstance
(
this
.
props
.
router
)
_containerProps
:
{...
this
.
props
}
}
}
}
}
...
@@ -43,25 +38,17 @@ export default class App extends Component {
...
@@ -43,25 +38,17 @@ export default class App extends Component {
}
}
export
class
Container
extends
Component
{
export
class
Container
extends
Component
{
static
contextTypes
=
{
_containerProps
:
PropTypes
.
any
}
componentDidMount
()
{
componentDidMount
()
{
this
.
scrollToHash
()
this
.
scrollToHash
()
}
}
shouldComponentUpdate
(
nextProps
)
{
// need this check not to rerender component which has already thrown an error
return
!
shallowEquals
(
this
.
props
,
nextProps
)
}
componentDidUpdate
()
{
componentDidUpdate
()
{
this
.
scrollToHash
()
this
.
scrollToHash
()
}
}
scrollToHash
()
{
scrollToHash
()
{
const
{
hash
}
=
this
.
context
.
_containerProps
let
{
hash
}
=
window
.
location
hash
=
hash
?
hash
.
substring
(
1
)
:
false
if
(
!
hash
)
return
if
(
!
hash
)
return
const
el
=
document
.
getElementById
(
hash
)
const
el
=
document
.
getElementById
(
hash
)
...
...
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