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
5f311cdd
Unverified
Commit
5f311cdd
authored
Dec 28, 2020
by
Joe Haddad
Committed by
GitHub
Dec 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix Fast Refresh tests with webpack@5 (#20543)
parent
f02bf210
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
36 deletions
+47
-36
build_test_deploy.yml
.github/workflows/build_test_deploy.yml
+1
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+1
-0
font-stylesheet-gathering-plugin.ts
...build/webpack/plugins/font-stylesheet-gathering-plugin.ts
+45
-35
No files found.
.github/workflows/build_test_deploy.yml
View file @
5f311cdd
...
...
@@ -148,7 +148,7 @@ jobs:
steps
:
-
uses
:
actions/checkout@v2
-
run
:
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
-
run
:
cat package.json | jq '.resolutions.webpack = "^5.
0.0-beta.30
"' > package.json.tmp && mv package.json.tmp package.json
-
run
:
cat package.json | jq '.resolutions.webpack = "^5.
11.1
"' > package.json.tmp && mv package.json.tmp package.json
-
run
:
cat package.json | jq '.resolutions.react = "^17.0.1"' > package.json.tmp && mv package.json.tmp package.json
-
run
:
cat package.json | jq '.resolutions."react-dom" = "^17.0.1"' > package.json.tmp && mv package.json.tmp package.json
-
run
:
yarn install --check-files
...
...
packages/next/build/webpack-config.ts
View file @
5f311cdd
...
...
@@ -1131,6 +1131,7 @@ export default async function getBaseWebpackConfig(
if
(
!
webpackConfig
.
optimization
)
{
webpackConfig
.
optimization
=
{}
}
webpackConfig
.
optimization
.
providedExports
=
false
webpackConfig
.
optimization
.
usedExports
=
false
}
...
...
packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts
View file @
5f311cdd
...
...
@@ -71,12 +71,12 @@ export class FontStylesheetGatheringPlugin {
return
}
let
result
if
(
node
.
name
===
'__jsx'
)
{
if
(
node
.
name
===
'_
jsx'
||
node
.
name
===
'_
_jsx'
)
{
result
=
new
BasicEvaluatedExpression
()
// @ts-ignore
result
.
setRange
(
node
.
range
)
result
.
setExpression
(
node
)
result
.
setIdentifier
(
'__jsx'
)
result
.
setIdentifier
(
node
.
name
)
// This was added webpack 5.
if
(
isWebpack5
)
{
...
...
@@ -86,44 +86,50 @@ export class FontStylesheetGatheringPlugin {
return
result
})
parser
.
hooks
.
call
.
for
(
'__jsx'
)
.
tap
(
this
.
constructor
.
name
,
(
node
:
namedTypes
.
CallExpression
)
=>
{
if
(
node
.
arguments
.
length
!==
2
)
{
// A font link tag has only two arguments rel=stylesheet and href='...'
return
}
if
(
!
isNodeCreatingLinkElement
(
node
))
{
const
jsxNodeHandler
=
(
node
:
namedTypes
.
CallExpression
)
=>
{
if
(
node
.
arguments
.
length
!==
2
)
{
// A font link tag has only two arguments rel=stylesheet and href='...'
return
}
if
(
!
isNodeCreatingLinkElement
(
node
))
{
return
}
// node.arguments[0] is the name of the tag and [1] are the props.
const
propsNode
=
node
.
arguments
[
1
]
as
namedTypes
.
ObjectExpression
const
props
:
{
[
key
:
string
]:
string
}
=
{}
propsNode
.
properties
.
forEach
((
prop
)
=>
{
if
(
prop
.
type
!==
'Property'
)
{
return
}
// node.arguments[0] is the name of the tag and [1] are the props.
const
propsNode
=
node
.
arguments
[
1
]
as
namedTypes
.
ObjectExpression
const
props
:
{
[
key
:
string
]:
string
}
=
{}
propsNode
.
properties
.
forEach
((
prop
)
=>
{
if
(
prop
.
type
!==
'Property'
)
{
return
}
if
(
prop
.
key
.
type
===
'Identifier'
&&
prop
.
value
.
type
===
'Literal'
)
{
props
[
prop
.
key
.
name
]
=
prop
.
value
.
value
as
string
}
})
if
(
!
props
.
rel
||
props
.
rel
!==
'stylesheet'
||
!
props
.
href
||
!
OPTIMIZED_FONT_PROVIDERS
.
some
((
url
)
=>
props
.
href
.
startsWith
(
url
)
)
prop
.
key
.
type
===
'Identifier'
&&
prop
.
value
.
type
===
'Literal'
)
{
return
false
props
[
prop
.
key
.
name
]
=
prop
.
value
.
value
as
string
}
this
.
gatheredStylesheets
.
push
(
props
.
href
)
})
if
(
!
props
.
rel
||
props
.
rel
!==
'stylesheet'
||
!
props
.
href
||
!
OPTIMIZED_FONT_PROVIDERS
.
some
((
url
)
=>
props
.
href
.
startsWith
(
url
)
)
)
{
return
false
}
this
.
gatheredStylesheets
.
push
(
props
.
href
)
}
// React JSX transform:
parser
.
hooks
.
call
.
for
(
'_jsx'
)
.
tap
(
this
.
constructor
.
name
,
jsxNodeHandler
)
// Next.js JSX transform:
parser
.
hooks
.
call
.
for
(
'__jsx'
)
.
tap
(
this
.
constructor
.
name
,
jsxNodeHandler
)
})
}
}
...
...
@@ -213,6 +219,10 @@ function isNodeCreatingLinkElement(node: namedTypes.CallExpression) {
if
(
componentNode
.
type
!==
'Literal'
)
{
return
false
}
// React has pragma: _jsx.
// Next has pragma: __jsx.
return
callee
.
name
===
'__jsx'
&&
componentNode
.
value
===
'link'
return
(
(
callee
.
name
===
'_jsx'
||
callee
.
name
===
'__jsx'
)
&&
componentNode
.
value
===
'link'
)
}
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