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
f3f939dd
Unverified
Commit
f3f939dd
authored
Aug 07, 2018
by
Tim Neutkens
Committed by
GitHub
Aug 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run method sorting codemod (#4909)
react-codemod recommended way of having methods defined
parent
80fdfec0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
104 additions
and
104 deletions
+104
-104
app.js
lib/app.js
+11
-11
link.js
lib/link.js
+26
-26
side-effect.js
lib/side-effect.js
+10
-10
document.js
server/document.js
+38
-38
bundle.js
test/integration/basic/pages/dynamic/bundle.js
+4
-4
shallow-routing.js
test/integration/basic/pages/nav/shallow-routing.js
+5
-5
bundle.js
test/integration/production/pages/dynamic/bundle.js
+4
-4
dynamic.js
test/integration/static/pages/dynamic.js
+2
-2
header-nav.js
test/integration/with-router/components/header-nav.js
+4
-4
No files found.
lib/app.js
View file @
f3f939dd
...
...
@@ -5,6 +5,12 @@ import { execOnce, warn, loadGetInitialProps } from './utils'
import
{
makePublicRouterInstance
}
from
'./router'
export
default
class
App
extends
Component
{
static
childContextTypes
=
{
_containerProps
:
PropTypes
.
any
,
headManager
:
PropTypes
.
object
,
router
:
PropTypes
.
object
}
static
displayName
=
'App'
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
...
...
@@ -12,12 +18,6 @@ export default class App extends Component {
return
{
pageProps
}
}
static
childContextTypes
=
{
_containerProps
:
PropTypes
.
any
,
headManager
:
PropTypes
.
object
,
router
:
PropTypes
.
object
}
getChildContext
()
{
const
{
headManager
}
=
this
.
props
return
{
...
...
@@ -51,6 +51,11 @@ export class Container extends Component {
this
.
scrollToHash
()
}
shouldComponentUpdate
(
nextProps
)
{
// need this check not to rerender component which has already thrown an error
return
!
shallowEquals
(
this
.
props
,
nextProps
)
}
componentDidUpdate
()
{
this
.
scrollToHash
()
}
...
...
@@ -67,11 +72,6 @@ export class Container extends Component {
setTimeout
(()
=>
el
.
scrollIntoView
(),
0
)
}
shouldComponentUpdate
(
nextProps
)
{
// need this check not to rerender component which has already thrown an error
return
!
shallowEquals
(
this
.
props
,
nextProps
)
}
render
()
{
const
{
children
}
=
this
.
props
return
<>
{
children
}
<
/
>
...
...
lib/link.js
View file @
f3f939dd
...
...
@@ -19,11 +19,6 @@ function isLocal (href) {
const
warnLink
=
execOnce
(
warn
)
class
Link
extends
Component
{
constructor
(
props
,
...
rest
)
{
super
(
props
,
...
rest
)
this
.
formatUrls
(
props
)
}
static
propTypes
=
exact
({
href
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]).
isRequired
,
as
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]),
...
...
@@ -46,11 +41,37 @@ class Link extends Component {
]).
isRequired
})
constructor
(
props
,
...
rest
)
{
super
(
props
,
...
rest
)
this
.
formatUrls
(
props
)
}
componentDidMount
()
{
this
.
prefetch
()
}
componentDidUpdate
(
prevProps
)
{
if
(
JSON
.
stringify
(
this
.
props
.
href
)
!==
JSON
.
stringify
(
prevProps
.
href
))
{
this
.
prefetch
()
}
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps
(
nextProps
)
{
this
.
formatUrls
(
nextProps
)
}
// We accept both 'href' and 'as' as objects which we can pass to `url.format`.
// We'll handle it here.
formatUrls
(
props
)
{
this
.
href
=
props
.
href
&&
typeof
props
.
href
===
'object'
?
format
(
props
.
href
)
:
props
.
href
this
.
as
=
props
.
as
&&
typeof
props
.
as
===
'object'
?
format
(
props
.
as
)
:
props
.
as
}
linkClicked
=
e
=>
{
const
{
nodeName
,
target
}
=
e
.
currentTarget
if
(
nodeName
===
'A'
&&
...
...
@@ -107,27 +128,6 @@ class Link extends Component {
Router
.
prefetch
(
href
)
}
componentDidMount
()
{
this
.
prefetch
()
}
componentDidUpdate
(
prevProps
)
{
if
(
JSON
.
stringify
(
this
.
props
.
href
)
!==
JSON
.
stringify
(
prevProps
.
href
))
{
this
.
prefetch
()
}
}
// We accept both 'href' and 'as' as objects which we can pass to `url.format`.
// We'll handle it here.
formatUrls
(
props
)
{
this
.
href
=
props
.
href
&&
typeof
props
.
href
===
'object'
?
format
(
props
.
href
)
:
props
.
href
this
.
as
=
props
.
as
&&
typeof
props
.
as
===
'object'
?
format
(
props
.
as
)
:
props
.
as
}
render
()
{
let
{
children
}
=
this
.
props
let
{
href
,
as
}
=
this
...
...
lib/side-effect.js
View file @
f3f939dd
...
...
@@ -34,13 +34,13 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
}
class
SideEffect
extends
Component
{
//
Try to use displayName of wrapped componen
t
static
displayName
=
`SideEffect(
${
getDisplayName
(
WrappedComponent
)}
)`
//
Expose canUseDOM so tests can monkeypatch i
t
static
canUseDOM
=
typeof
window
!==
'undefined'
static
contextTypes
=
WrappedComponent
.
contextTypes
//
Expose canUseDOM so tests can monkeypatch i
t
static
canUseDOM
=
typeof
window
!==
'undefined'
//
Try to use displayName of wrapped componen
t
static
displayName
=
`SideEffect(
${
getDisplayName
(
WrappedComponent
)}
)`
static
peek
()
{
return
state
...
...
@@ -57,12 +57,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
return
recordedState
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount
()
{
mountedInstances
.
add
(
this
)
emitChange
(
this
)
}
componentDidUpdate
()
{
emitChange
(
this
)
}
...
...
@@ -72,6 +66,12 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
emitChange
(
this
)
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount
()
{
mountedInstances
.
add
(
this
)
emitChange
(
this
)
}
render
()
{
return
<
WrappedComponent
>
{
this
.
props
.
children
}
<
/WrappedComponent
>
}
...
...
server/document.js
View file @
f3f939dd
...
...
@@ -9,16 +9,16 @@ const Fragment = React.Fragment || function Fragment ({ children }) {
}
export
default
class
Document
extends
Component
{
static
childContextTypes
=
{
_documentProps
:
PropTypes
.
any
}
static
getInitialProps
({
renderPage
})
{
const
{
html
,
head
,
errorHtml
,
buildManifest
}
=
renderPage
()
const
styles
=
flush
()
return
{
html
,
head
,
errorHtml
,
styles
,
buildManifest
}
}
static
childContextTypes
=
{
_documentProps
:
PropTypes
.
any
}
getChildContext
()
{
return
{
_documentProps
:
this
.
props
}
}
...
...
@@ -43,58 +43,58 @@ export class Head extends Component {
nonce
:
PropTypes
.
string
}
get
PreloadMain
Links
()
{
get
Css
Links
()
{
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
if
(
!
files
||
files
.
length
===
0
)
{
return
null
}
return
files
.
map
((
file
)
=>
{
// Only render .
j
s files here
if
(
!
/
\.
j
s$/
.
exec
(
file
))
{
// Only render .
cs
s files here
if
(
!
/
\.
cs
s$/
.
exec
(
file
))
{
return
null
}
return
<
link
key
=
{
file
}
nonce
=
{
this
.
props
.
nonce
}
rel
=
'
preload
'
rel
=
'
stylesheet
'
href
=
{
`
${
assetPrefix
}
/_next/
${
file
}
`
}
/
>
})
}
getPreloadDynamicChunks
()
{
const
{
dynamicImports
,
assetPrefix
}
=
this
.
context
.
_documentProps
return
dynamicImports
.
map
((
bundle
)
=>
{
return
<
script
async
key
=
{
bundle
.
file
}
src
=
{
`
${
assetPrefix
}
/_next/
${
bundle
.
file
}
`
}
as
=
'script'
nonce
=
{
this
.
props
.
nonce
}
/
>
})
}
get
Css
Links
()
{
get
PreloadMain
Links
()
{
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
if
(
!
files
||
files
.
length
===
0
)
{
return
null
}
return
files
.
map
((
file
)
=>
{
// Only render .
cs
s files here
if
(
!
/
\.
cs
s$/
.
exec
(
file
))
{
// Only render .
j
s files here
if
(
!
/
\.
j
s$/
.
exec
(
file
))
{
return
null
}
return
<
link
key
=
{
file
}
nonce
=
{
this
.
props
.
nonce
}
rel
=
'
stylesheet
'
rel
=
'
preload
'
href
=
{
`
${
assetPrefix
}
/_next/
${
file
}
`
}
/
>
})
}
getPreloadDynamicChunks
()
{
const
{
dynamicImports
,
assetPrefix
}
=
this
.
context
.
_documentProps
return
dynamicImports
.
map
((
bundle
)
=>
{
return
<
script
async
key
=
{
bundle
.
file
}
src
=
{
`
${
assetPrefix
}
/_next/
${
bundle
.
file
}
`
}
as
=
'script'
nonce
=
{
this
.
props
.
nonce
}
/>
})
}
...
...
@@ -135,12 +135,24 @@ export class Main extends Component {
}
export
class
NextScript
extends
Component
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
}
static
propTypes
=
{
nonce
:
PropTypes
.
string
}
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
getDynamicChunks
()
{
const
{
dynamicImports
,
assetPrefix
}
=
this
.
context
.
_documentProps
return
dynamicImports
.
map
((
bundle
)
=>
{
return
<
script
async
key
=
{
bundle
.
file
}
src
=
{
`
${
assetPrefix
}
/_next/
${
bundle
.
file
}
`
}
nonce
=
{
this
.
props
.
nonce
}
/
>
})
}
getScripts
()
{
...
...
@@ -164,18 +176,6 @@ export class NextScript extends Component {
})
}
getDynamicChunks
()
{
const
{
dynamicImports
,
assetPrefix
}
=
this
.
context
.
_documentProps
return
dynamicImports
.
map
((
bundle
)
=>
{
return
<
script
async
key
=
{
bundle
.
file
}
src
=
{
`
${
assetPrefix
}
/_next/
${
bundle
.
file
}
`
}
nonce
=
{
this
.
props
.
nonce
}
/
>
})
}
render
()
{
const
{
staticMarkup
,
assetPrefix
,
__NEXT_DATA__
}
=
this
.
context
.
_documentProps
const
{
page
,
pathname
,
buildId
}
=
__NEXT_DATA__
...
...
test/integration/basic/pages/dynamic/bundle.js
View file @
f3f939dd
...
...
@@ -24,14 +24,14 @@ const HelloBundle = dynamic({
})
export
default
class
Bundle
extends
React
.
Component
{
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
static
childContextTypes
=
{
data
:
PropTypes
.
object
}
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
getChildContext
()
{
return
{
data
:
{
title
:
'ZEIT Rocks'
}
...
...
test/integration/basic/pages/nav/shallow-routing.js
View file @
f3f939dd
...
...
@@ -16,17 +16,17 @@ export default class extends Component {
return
{
getInitialPropsRunCount
}
}
getCurrentCounter
()
{
const
{
url
}
=
this
.
props
return
url
.
query
.
counter
?
parseInt
(
url
.
query
.
counter
)
:
0
}
increase
()
{
const
counter
=
this
.
getCurrentCounter
()
const
href
=
`/nav/shallow-routing?counter=
${
counter
+
1
}
`
Router
.
push
(
href
,
href
,
{
shallow
:
true
})
}
getCurrentCounter
()
{
const
{
url
}
=
this
.
props
return
url
.
query
.
counter
?
parseInt
(
url
.
query
.
counter
)
:
0
}
render
()
{
return
(
<
div
className
=
'shallow-routing'
>
...
...
test/integration/production/pages/dynamic/bundle.js
View file @
f3f939dd
...
...
@@ -23,14 +23,14 @@ const HelloBundle = dynamic({
})
export
default
class
Bundle
extends
React
.
Component
{
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
static
childContextTypes
=
{
data
:
PropTypes
.
object
}
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
getChildContext
()
{
return
{
data
:
{
title
:
'ZEIT Rocks'
}
...
...
test/integration/static/pages/dynamic.js
View file @
f3f939dd
...
...
@@ -3,12 +3,12 @@ import React from 'react'
import
Link
from
'next/link'
export
default
class
DynamicPage
extends
React
.
Component
{
state
=
{}
static
getInitialProps
({
query
})
{
return
{
text
:
query
.
text
}
}
state
=
{}
componentDidMount
()
{
const
[,
hash
]
=
location
.
href
.
split
(
'#'
)
this
.
setState
({
hash
})
...
...
test/integration/with-router/components/header-nav.js
View file @
f3f939dd
...
...
@@ -30,9 +30,9 @@ class HeaderNav extends React.Component {
this
.
props
.
router
.
events
.
off
(
'routeChangeComplete'
,
this
.
handleRouteChange
)
}
handleRouteChange
TopLevelRouterDeprecatedBehavior
=
url
=>
{
handleRouteChange
=
url
=>
{
this
.
setState
({
activeURL
TopLevelRouterDeprecatedBehavior
:
url
activeURL
:
url
})
};
...
...
@@ -42,9 +42,9 @@ class HeaderNav extends React.Component {
})
};
handleRouteChange
=
url
=>
{
handleRouteChange
TopLevelRouterDeprecatedBehavior
=
url
=>
{
this
.
setState
({
activeURL
:
url
activeURL
TopLevelRouterDeprecatedBehavior
:
url
})
};
...
...
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