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
74909ecf
Unverified
Commit
74909ecf
authored
Dec 30, 2020
by
Alex Castle
Committed by
GitHub
Dec 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move CSS Preloads to top of head at document render (#18864)
Co-authored-by:
Joe Haddad
<
joe.haddad@zeit.co
>
parent
cc0dcf96
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
0 deletions
+45
-0
_document.tsx
packages/next/pages/_document.tsx
+17
-0
index.js
test/integration/image-component/basic/pages/index.js
+5
-0
styles.css
test/integration/image-component/basic/public/styles.css
+3
-0
index.test.js
test/integration/image-component/basic/test/index.test.js
+20
-0
No files found.
packages/next/pages/_document.tsx
View file @
74909ecf
...
...
@@ -348,6 +348,23 @@ export class Head extends Component<
this
.
context
.
docComponentsRendered
.
Head
=
true
let
{
head
}
=
this
.
context
let
cssPreloads
:
Array
<
JSX
.
Element
>
=
[]
let
otherHeadElements
:
Array
<
JSX
.
Element
>
=
[]
if
(
head
)
{
head
.
forEach
((
c
)
=>
{
if
(
c
&&
c
.
type
===
'link'
&&
c
.
props
[
'rel'
]
===
'preload'
&&
c
.
props
[
'as'
]
===
'style'
)
{
cssPreloads
.
push
(
c
)
}
else
{
c
&&
otherHeadElements
.
push
(
c
)
}
})
head
=
cssPreloads
.
concat
(
otherHeadElements
)
}
let
children
=
this
.
props
.
children
// show a warning if Head contains <title> (only in development)
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
...
...
test/integration/image-component/basic/pages/index.js
View file @
74909ecf
import
React
from
'react'
import
Image
from
'next/image'
import
Link
from
'next/link'
import
Head
from
'next/head'
const
Page
=
()
=>
{
return
(
...
...
@@ -90,6 +91,10 @@ const Page = () => {
<
Link
href
=
"/lazy"
>
<
a
id
=
"lazylink"
>
lazy
<
/a
>
<
/Link
>
<
Head
>
<
link
rel
=
"stylesheet"
href
=
"styles.css"
/>
<
link
rel
=
"preload"
href
=
"styles.css"
as
=
"style"
/>
<
/Head
>
<
p
id
=
"stubtext"
>
This
is
the
index
page
<
/p
>
<
/div
>
)
...
...
test/integration/image-component/basic/public/styles.css
0 → 100644
View file @
74909ecf
p
{
color
:
red
;
}
test/integration/image-component/basic/test/index.test.js
View file @
74909ecf
...
...
@@ -202,6 +202,23 @@ async function hasPreloadLinkMatchingUrl(url) {
return
false
}
async
function
hasImagePreloadBeforeCSSPreload
()
{
const
links
=
await
browser
.
elementsByCss
(
'link'
)
let
foundImage
=
false
for
(
const
link
of
links
)
{
const
rel
=
await
link
.
getAttribute
(
'rel'
)
if
(
rel
===
'preload'
)
{
const
linkAs
=
await
link
.
getAttribute
(
'as'
)
if
(
linkAs
===
'image'
)
{
foundImage
=
true
}
else
if
(
linkAs
===
'style'
&&
foundImage
)
{
return
true
}
}
}
return
false
}
describe
(
'Image Component Tests'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
...
...
@@ -245,6 +262,9 @@ describe('Image Component Tests', () => {
)
).
toBe
(
true
)
})
it
(
'should not create any preload tags higher up the page than CSS preload tags'
,
async
()
=>
{
expect
(
await
hasImagePreloadBeforeCSSPreload
()).
toBe
(
false
)
})
})
describe
(
'Client-side Image Component Tests'
,
()
=>
{
beforeAll
(
async
()
=>
{
...
...
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