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
9b0c641b
Commit
9b0c641b
authored
Sep 19, 2019
by
Luc
Committed by
Joe Haddad
Sep 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Insert <style> tags after anchor element (#8795)
* insert css *after* noscript tag in dev mode * use arrow function
parent
0eda4d59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
webpack-config.ts
packages/next/build/webpack-config.ts
+26
-4
No files found.
packages/next/build/webpack-config.ts
View file @
9b0c641b
...
...
@@ -564,10 +564,32 @@ export default async function getBaseWebpackConfig(
options
:
{
// By default, style-loader injects CSS into the bottom
// of <head>. This causes ordering problems between dev
// and prod. To fix this, we render a <noscript> tag for
// the styles to be placed within. These styles will be
// applied _before_ <style jsx global>.
insert
:
`#__next_css__DO_NOT_USE__`
,
// and prod. To fix this, we render a <noscript> tag as
// an "anchor" for the styles to be placed after. These
// styles will be applied _before_ <style jsx global>.
insert
:
(
element
:
Node
)
=>
{
const
parent
=
document
.
querySelector
(
'head'
)
as
Element
const
anchor
=
document
.
querySelector
(
'#__next_css__DO_NOT_USE__'
)
// @ts-ignore
const
lastInsert
=
window
.
__lastInsertedByStyleLoader
if
(
lastInsert
&&
lastInsert
.
nextSibling
)
{
// if a style element was already inserted, insert after
parent
.
insertBefore
(
element
,
lastInsert
.
nextSibling
)
}
else
if
(
anchor
&&
anchor
.
nextSibling
)
{
// else, insert after the anchor
parent
.
insertBefore
(
element
,
anchor
.
nextSibling
)
}
else
{
// fallback to inserting in last position into head
parent
.
appendChild
(
element
)
}
// @ts-ignore
window
.
__lastInsertedByStyleLoader
=
element
},
},
},
// When building for production we extract CSS into
...
...
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