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'
...
@@ -5,6 +5,12 @@ import { execOnce, warn, 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
=
{
_containerProps
:
PropTypes
.
any
,
headManager
:
PropTypes
.
object
,
router
:
PropTypes
.
object
}
static
displayName
=
'App'
static
displayName
=
'App'
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
static
async
getInitialProps
({
Component
,
router
,
ctx
})
{
...
@@ -12,12 +18,6 @@ export default class App extends Component {
...
@@ -12,12 +18,6 @@ export default class App extends Component {
return
{
pageProps
}
return
{
pageProps
}
}
}
static
childContextTypes
=
{
_containerProps
:
PropTypes
.
any
,
headManager
:
PropTypes
.
object
,
router
:
PropTypes
.
object
}
getChildContext
()
{
getChildContext
()
{
const
{
headManager
}
=
this
.
props
const
{
headManager
}
=
this
.
props
return
{
return
{
...
@@ -51,6 +51,11 @@ export class Container extends Component {
...
@@ -51,6 +51,11 @@ export class Container extends Component {
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
()
}
}
...
@@ -67,11 +72,6 @@ export class Container extends Component {
...
@@ -67,11 +72,6 @@ export class Container extends Component {
setTimeout
(()
=>
el
.
scrollIntoView
(),
0
)
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
()
{
render
()
{
const
{
children
}
=
this
.
props
const
{
children
}
=
this
.
props
return
<>
{
children
}
<
/
>
return
<>
{
children
}
<
/
>
...
...
lib/link.js
View file @
f3f939dd
...
@@ -19,11 +19,6 @@ function isLocal (href) {
...
@@ -19,11 +19,6 @@ function isLocal (href) {
const
warnLink
=
execOnce
(
warn
)
const
warnLink
=
execOnce
(
warn
)
class
Link
extends
Component
{
class
Link
extends
Component
{
constructor
(
props
,
...
rest
)
{
super
(
props
,
...
rest
)
this
.
formatUrls
(
props
)
}
static
propTypes
=
exact
({
static
propTypes
=
exact
({
href
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]).
isRequired
,
href
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]).
isRequired
,
as
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]),
as
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]),
...
@@ -46,11 +41,37 @@ class Link extends Component {
...
@@ -46,11 +41,37 @@ class Link extends Component {
]).
isRequired
]).
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
// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps
(
nextProps
)
{
UNSAFE_componentWillReceiveProps
(
nextProps
)
{
this
.
formatUrls
(
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
=>
{
linkClicked
=
e
=>
{
const
{
nodeName
,
target
}
=
e
.
currentTarget
const
{
nodeName
,
target
}
=
e
.
currentTarget
if
(
nodeName
===
'A'
&&
if
(
nodeName
===
'A'
&&
...
@@ -107,27 +128,6 @@ class Link extends Component {
...
@@ -107,27 +128,6 @@ class Link extends Component {
Router
.
prefetch
(
href
)
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
()
{
render
()
{
let
{
children
}
=
this
.
props
let
{
children
}
=
this
.
props
let
{
href
,
as
}
=
this
let
{
href
,
as
}
=
this
...
...
lib/side-effect.js
View file @
f3f939dd
...
@@ -34,13 +34,13 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
...
@@ -34,13 +34,13 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
}
}
class
SideEffect
extends
Component
{
class
SideEffect
extends
Component
{
//
Try to use displayName of wrapped componen
t
//
Expose canUseDOM so tests can monkeypatch i
t
static
displayName
=
`SideEffect(
${
getDisplayName
(
WrappedComponent
)}
)`
static
canUseDOM
=
typeof
window
!==
'undefined'
static
contextTypes
=
WrappedComponent
.
contextTypes
static
contextTypes
=
WrappedComponent
.
contextTypes
//
Expose canUseDOM so tests can monkeypatch i
t
//
Try to use displayName of wrapped componen
t
static
canUseDOM
=
typeof
window
!==
'undefined'
static
displayName
=
`SideEffect(
${
getDisplayName
(
WrappedComponent
)}
)`
static
peek
()
{
static
peek
()
{
return
state
return
state
...
@@ -57,12 +57,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
...
@@ -57,12 +57,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
return
recordedState
return
recordedState
}
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount
()
{
mountedInstances
.
add
(
this
)
emitChange
(
this
)
}
componentDidUpdate
()
{
componentDidUpdate
()
{
emitChange
(
this
)
emitChange
(
this
)
}
}
...
@@ -72,6 +66,12 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
...
@@ -72,6 +66,12 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
emitChange
(
this
)
emitChange
(
this
)
}
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount
()
{
mountedInstances
.
add
(
this
)
emitChange
(
this
)
}
render
()
{
render
()
{
return
<
WrappedComponent
>
{
this
.
props
.
children
}
<
/WrappedComponent
>
return
<
WrappedComponent
>
{
this
.
props
.
children
}
<
/WrappedComponent
>
}
}
...
...
server/document.js
View file @
f3f939dd
...
@@ -9,16 +9,16 @@ const Fragment = React.Fragment || function Fragment ({ children }) {
...
@@ -9,16 +9,16 @@ const Fragment = React.Fragment || function Fragment ({ children }) {
}
}
export
default
class
Document
extends
Component
{
export
default
class
Document
extends
Component
{
static
childContextTypes
=
{
_documentProps
:
PropTypes
.
any
}
static
getInitialProps
({
renderPage
})
{
static
getInitialProps
({
renderPage
})
{
const
{
html
,
head
,
errorHtml
,
buildManifest
}
=
renderPage
()
const
{
html
,
head
,
errorHtml
,
buildManifest
}
=
renderPage
()
const
styles
=
flush
()
const
styles
=
flush
()
return
{
html
,
head
,
errorHtml
,
styles
,
buildManifest
}
return
{
html
,
head
,
errorHtml
,
styles
,
buildManifest
}
}
}
static
childContextTypes
=
{
_documentProps
:
PropTypes
.
any
}
getChildContext
()
{
getChildContext
()
{
return
{
_documentProps
:
this
.
props
}
return
{
_documentProps
:
this
.
props
}
}
}
...
@@ -43,58 +43,58 @@ export class Head extends Component {
...
@@ -43,58 +43,58 @@ export class Head extends Component {
nonce
:
PropTypes
.
string
nonce
:
PropTypes
.
string
}
}
get
PreloadMain
Links
()
{
get
Css
Links
()
{
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
if
(
!
files
||
files
.
length
===
0
)
{
if
(
!
files
||
files
.
length
===
0
)
{
return
null
return
null
}
}
return
files
.
map
((
file
)
=>
{
return
files
.
map
((
file
)
=>
{
// Only render .
j
s files here
// Only render .
cs
s files here
if
(
!
/
\.
j
s$/
.
exec
(
file
))
{
if
(
!
/
\.
cs
s$/
.
exec
(
file
))
{
return
null
return
null
}
}
return
<
link
return
<
link
key
=
{
file
}
key
=
{
file
}
nonce
=
{
this
.
props
.
nonce
}
nonce
=
{
this
.
props
.
nonce
}
rel
=
'
preload
'
rel
=
'
stylesheet
'
href
=
{
`
${
assetPrefix
}
/_next/
${
file
}
`
}
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'
as
=
'script'
nonce
=
{
this
.
props
.
nonce
}
/
>
/
>
})
})
}
}
get
Css
Links
()
{
get
PreloadMain
Links
()
{
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
if
(
!
files
||
files
.
length
===
0
)
{
if
(
!
files
||
files
.
length
===
0
)
{
return
null
return
null
}
}
return
files
.
map
((
file
)
=>
{
return
files
.
map
((
file
)
=>
{
// Only render .
cs
s files here
// Only render .
j
s files here
if
(
!
/
\.
cs
s$/
.
exec
(
file
))
{
if
(
!
/
\.
j
s$/
.
exec
(
file
))
{
return
null
return
null
}
}
return
<
link
return
<
link
key
=
{
file
}
key
=
{
file
}
nonce
=
{
this
.
props
.
nonce
}
nonce
=
{
this
.
props
.
nonce
}
rel
=
'
stylesheet
'
rel
=
'
preload
'
href
=
{
`
${
assetPrefix
}
/_next/
${
file
}
`
}
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'
as
=
'script'
nonce
=
{
this
.
props
.
nonce
}
/>
/>
})
})
}
}
...
@@ -135,12 +135,24 @@ export class Main extends Component {
...
@@ -135,12 +135,24 @@ export class Main extends Component {
}
}
export
class
NextScript
extends
Component
{
export
class
NextScript
extends
Component
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
}
static
propTypes
=
{
static
propTypes
=
{
nonce
:
PropTypes
.
string
nonce
:
PropTypes
.
string
}
}
static
contextTypes
=
{
getDynamicChunks
()
{
_documentProps
:
PropTypes
.
any
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
()
{
getScripts
()
{
...
@@ -164,18 +176,6 @@ export class NextScript extends Component {
...
@@ -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
()
{
render
()
{
const
{
staticMarkup
,
assetPrefix
,
__NEXT_DATA__
}
=
this
.
context
.
_documentProps
const
{
staticMarkup
,
assetPrefix
,
__NEXT_DATA__
}
=
this
.
context
.
_documentProps
const
{
page
,
pathname
,
buildId
}
=
__NEXT_DATA__
const
{
page
,
pathname
,
buildId
}
=
__NEXT_DATA__
...
...
test/integration/basic/pages/dynamic/bundle.js
View file @
f3f939dd
...
@@ -24,14 +24,14 @@ const HelloBundle = dynamic({
...
@@ -24,14 +24,14 @@ const HelloBundle = dynamic({
})
})
export
default
class
Bundle
extends
React
.
Component
{
export
default
class
Bundle
extends
React
.
Component
{
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
static
childContextTypes
=
{
static
childContextTypes
=
{
data
:
PropTypes
.
object
data
:
PropTypes
.
object
}
}
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
getChildContext
()
{
getChildContext
()
{
return
{
return
{
data
:
{
title
:
'ZEIT Rocks'
}
data
:
{
title
:
'ZEIT Rocks'
}
...
...
test/integration/basic/pages/nav/shallow-routing.js
View file @
f3f939dd
...
@@ -16,17 +16,17 @@ export default class extends Component {
...
@@ -16,17 +16,17 @@ export default class extends Component {
return
{
getInitialPropsRunCount
}
return
{
getInitialPropsRunCount
}
}
}
getCurrentCounter
()
{
const
{
url
}
=
this
.
props
return
url
.
query
.
counter
?
parseInt
(
url
.
query
.
counter
)
:
0
}
increase
()
{
increase
()
{
const
counter
=
this
.
getCurrentCounter
()
const
counter
=
this
.
getCurrentCounter
()
const
href
=
`/nav/shallow-routing?counter=
${
counter
+
1
}
`
const
href
=
`/nav/shallow-routing?counter=
${
counter
+
1
}
`
Router
.
push
(
href
,
href
,
{
shallow
:
true
})
Router
.
push
(
href
,
href
,
{
shallow
:
true
})
}
}
getCurrentCounter
()
{
const
{
url
}
=
this
.
props
return
url
.
query
.
counter
?
parseInt
(
url
.
query
.
counter
)
:
0
}
render
()
{
render
()
{
return
(
return
(
<
div
className
=
'shallow-routing'
>
<
div
className
=
'shallow-routing'
>
...
...
test/integration/production/pages/dynamic/bundle.js
View file @
f3f939dd
...
@@ -23,14 +23,14 @@ const HelloBundle = dynamic({
...
@@ -23,14 +23,14 @@ const HelloBundle = dynamic({
})
})
export
default
class
Bundle
extends
React
.
Component
{
export
default
class
Bundle
extends
React
.
Component
{
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
static
childContextTypes
=
{
static
childContextTypes
=
{
data
:
PropTypes
.
object
data
:
PropTypes
.
object
}
}
static
getInitialProps
({
query
})
{
return
{
showMore
:
Boolean
(
query
.
showMore
)
}
}
getChildContext
()
{
getChildContext
()
{
return
{
return
{
data
:
{
title
:
'ZEIT Rocks'
}
data
:
{
title
:
'ZEIT Rocks'
}
...
...
test/integration/static/pages/dynamic.js
View file @
f3f939dd
...
@@ -3,12 +3,12 @@ import React from 'react'
...
@@ -3,12 +3,12 @@ import React from 'react'
import
Link
from
'next/link'
import
Link
from
'next/link'
export
default
class
DynamicPage
extends
React
.
Component
{
export
default
class
DynamicPage
extends
React
.
Component
{
state
=
{}
static
getInitialProps
({
query
})
{
static
getInitialProps
({
query
})
{
return
{
text
:
query
.
text
}
return
{
text
:
query
.
text
}
}
}
state
=
{}
componentDidMount
()
{
componentDidMount
()
{
const
[,
hash
]
=
location
.
href
.
split
(
'#'
)
const
[,
hash
]
=
location
.
href
.
split
(
'#'
)
this
.
setState
({
hash
})
this
.
setState
({
hash
})
...
...
test/integration/with-router/components/header-nav.js
View file @
f3f939dd
...
@@ -30,9 +30,9 @@ class HeaderNav extends React.Component {
...
@@ -30,9 +30,9 @@ class HeaderNav extends React.Component {
this
.
props
.
router
.
events
.
off
(
'routeChangeComplete'
,
this
.
handleRouteChange
)
this
.
props
.
router
.
events
.
off
(
'routeChangeComplete'
,
this
.
handleRouteChange
)
}
}
handleRouteChange
TopLevelRouterDeprecatedBehavior
=
url
=>
{
handleRouteChange
=
url
=>
{
this
.
setState
({
this
.
setState
({
activeURL
TopLevelRouterDeprecatedBehavior
:
url
activeURL
:
url
})
})
};
};
...
@@ -42,9 +42,9 @@ class HeaderNav extends React.Component {
...
@@ -42,9 +42,9 @@ class HeaderNav extends React.Component {
})
})
};
};
handleRouteChange
=
url
=>
{
handleRouteChange
TopLevelRouterDeprecatedBehavior
=
url
=>
{
this
.
setState
({
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