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
9174b7a3
Unverified
Commit
9174b7a3
authored
Nov 13, 2020
by
Joe Haddad
Committed by
GitHub
Nov 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix component lifecycle order for style swap (#19125)
Co-authored-by:
Gerald Monaco
<
gbmonaco@google.com
>
parent
f108dbf2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
3 deletions
+139
-3
index.tsx
packages/next/client/index.tsx
+14
-2
index.js
.../integration/css-fixtures/transition-react/pages/index.js
+11
-0
other.js
.../integration/css-fixtures/transition-react/pages/other.js
+34
-0
other.module.css
...tion/css-fixtures/transition-react/pages/other.module.css
+3
-0
index.test.js
test/integration/css/test/index.test.js
+76
-0
index.test.js
test/integration/size-limit/test/index.test.js
+1
-1
No files found.
packages/next/client/index.tsx
View file @
9174b7a3
...
@@ -661,7 +661,7 @@ function doRender(input: RenderRouteInfo): Promise<any> {
...
@@ -661,7 +661,7 @@ function doRender(input: RenderRouteInfo): Promise<any> {
return
true
return
true
}
}
function
onCommit
()
{
function
on
Head
Commit
()
{
if
(
if
(
// We use `style-loader` in development, so we don't need to do anything
// We use `style-loader` in development, so we don't need to do anything
// unless we're in production:
// unless we're in production:
...
@@ -723,12 +723,15 @@ function doRender(input: RenderRouteInfo): Promise<any> {
...
@@ -723,12 +723,15 @@ function doRender(input: RenderRouteInfo): Promise<any> {
// unstyled content:
// unstyled content:
getComputedStyle
(
document
.
body
,
'height'
)
getComputedStyle
(
document
.
body
,
'height'
)
}
}
}
function
onRootCommit
()
{
resolvePromise
()
resolvePromise
()
}
}
const
elem
=
(
const
elem
=
(
<
Root
callback=
{
onCommit
}
>
<
Root
callback=
{
onRootCommit
}
>
<
Head
callback=
{
onHeadCommit
}
/>
<
AppContainer
>
<
AppContainer
>
<
App
{
...
appProps
}
/>
<
App
{
...
appProps
}
/>
</
AppContainer
>
</
AppContainer
>
...
@@ -776,3 +779,12 @@ function Root({
...
@@ -776,3 +779,12 @@ function Root({
},
[])
},
[])
return
children
as
React
.
ReactElement
return
children
as
React
.
ReactElement
}
}
// Dummy component that we render as a child of Root so that we can
// toggle the correct styles before the page is rendered.
function Head(
{
callback
}
:
{
callback
:
()
=>
void
}
)
{
// We use `useLayoutEffect` to guarantee the callback is executed
// as soon as React flushes the update.
React
.
useLayoutEffect
(()
=>
callback
(),
[
callback
])
return
null
}
test/integration/css-fixtures/transition-react/pages/index.js
0 → 100644
View file @
9174b7a3
import
Link
from
'next/link'
export
default
function
Home
()
{
return
(
<
main
>
<
Link
href
=
"/other"
prefetch
=
{
false
}
>
<
a
id
=
"link-other"
>
other
<
/a
>
<
/Link
>
<
/main
>
)
}
test/integration/css-fixtures/transition-react/pages/other.js
0 → 100644
View file @
9174b7a3
import
React
from
'react'
import
Link
from
'next/link'
import
css
from
'./other.module.css'
export
default
class
Other
extends
React
.
Component
{
ref
=
React
.
createRef
()
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
color
:
null
,
}
}
componentDidMount
()
{
this
.
setState
({
color
:
window
.
getComputedStyle
(
this
.
ref
.
current
).
color
,
})
}
render
()
{
return
(
<
main
>
<
Link
href
=
"/"
prefetch
=
{
false
}
>
<
a
id
=
"link-index"
>
index
page
<
/a
>
<
/Link
>
<
br
/>
<
h1
id
=
"red-title"
className
=
{
css
.
root
}
ref
=
{
this
.
ref
}
>
{
this
.
state
.
color
}
<
/h1
>
<
/main
>
)
}
}
test/integration/css-fixtures/transition-react/pages/other.module.css
0 → 100644
View file @
9174b7a3
.root
{
color
:
red
;
}
test/integration/css/test/index.test.js
View file @
9174b7a3
...
@@ -245,6 +245,82 @@ describe('CSS Support', () => {
...
@@ -245,6 +245,82 @@ describe('CSS Support', () => {
})
})
})
})
describe
(
'React Lifecyce Order (dev)'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'transition-react'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
let
appPort
let
app
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
})
afterAll
(
async
()
=>
{
await
killApp
(
app
)
})
it
(
'should have the correct color on mount after navigation'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
appPort
,
'/'
)
// Navigate to other:
await
browser
.
waitForElementByCss
(
'#link-other'
).
click
()
const
text
=
await
browser
.
waitForElementByCss
(
'#red-title'
).
text
()
expect
(
text
).
toMatchInlineSnapshot
(
`"rgb(255, 0, 0)"`
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
}
}
})
})
describe
(
'React Lifecyce Order (production)'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'transition-react'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
let
appPort
let
app
let
code
let
stdout
beforeAll
(
async
()
=>
{
;({
code
,
stdout
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
}))
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(
async
()
=>
{
await
killApp
(
app
)
})
it
(
'should have compiled successfully'
,
()
=>
{
expect
(
code
).
toBe
(
0
)
expect
(
stdout
).
toMatch
(
/Compiled successfully/
)
})
it
(
'should have the correct color on mount after navigation'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
appPort
,
'/'
)
// Navigate to other:
await
browser
.
waitForElementByCss
(
'#link-other'
).
click
()
const
text
=
await
browser
.
waitForElementByCss
(
'#red-title'
).
text
()
expect
(
text
).
toMatchInlineSnapshot
(
`"rgb(255, 0, 0)"`
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
}
}
})
})
describe
(
'Invalid CSS in _document'
,
()
=>
{
describe
(
'Invalid CSS in _document'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'invalid-module-document'
)
const
appDir
=
join
(
fixturesDir
,
'invalid-module-document'
)
...
...
test/integration/size-limit/test/index.test.js
View file @
9174b7a3
...
@@ -80,7 +80,7 @@ describe('Production response size', () => {
...
@@ -80,7 +80,7 @@ describe('Production response size', () => {
)
)
// These numbers are without gzip compression!
// These numbers are without gzip compression!
const
delta
=
responseSizesBytes
-
28
2
*
1024
const
delta
=
responseSizesBytes
-
28
3
*
1024
expect
(
delta
).
toBeLessThanOrEqual
(
1024
)
// don't increase size more than 1kb
expect
(
delta
).
toBeLessThanOrEqual
(
1024
)
// don't increase size more than 1kb
expect
(
delta
).
toBeGreaterThanOrEqual
(
-
1024
)
// don't decrease size more than 1kb without updating target
expect
(
delta
).
toBeGreaterThanOrEqual
(
-
1024
)
// don't decrease size more than 1kb without updating target
})
})
...
...
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