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
cac35c38
Unverified
Commit
cac35c38
authored
Jul 30, 2020
by
Joe Haddad
Committed by
GitHub
Jul 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hot reloader edge case with broken webpack plugins (#15659)
parent
6b0c4948
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
6 deletions
+91
-6
hot-reloader.ts
packages/next/server/hot-reloader.ts
+28
-4
middleware.ts
packages/react-dev-overlay/src/middleware.ts
+2
-2
next.config.js
test/integration/broken-webpack-plugin/next.config.js
+16
-0
index.js
test/integration/broken-webpack-plugin/pages/index.js
+3
-0
index.test.js
test/integration/broken-webpack-plugin/test/index.test.js
+42
-0
No files found.
packages/next/server/hot-reloader.ts
View file @
cac35c38
...
@@ -143,8 +143,10 @@ export default class HotReloader {
...
@@ -143,8 +143,10 @@ export default class HotReloader {
private
pagesDir
:
string
private
pagesDir
:
string
private
webpackHotMiddleware
:
(
NextHandleFunction
&
any
)
|
null
private
webpackHotMiddleware
:
(
NextHandleFunction
&
any
)
|
null
private
config
:
any
private
config
:
any
private
stats
:
any
private
stats
:
webpack
.
Stats
|
null
private
serverStats
:
any
private
serverStats
:
webpack
.
Stats
|
null
private
clientError
:
Error
|
null
=
null
private
serverError
:
Error
|
null
=
null
private
serverPrevDocumentHash
:
string
|
null
private
serverPrevDocumentHash
:
string
|
null
private
prevChunkNames
?:
Set
<
any
>
private
prevChunkNames
?:
Set
<
any
>
private
onDemandEntries
:
any
private
onDemandEntries
:
any
...
@@ -349,9 +351,17 @@ export default class HotReloader {
...
@@ -349,9 +351,17 @@ export default class HotReloader {
watchCompilers
(
multiCompiler
.
compilers
[
0
],
multiCompiler
.
compilers
[
1
])
watchCompilers
(
multiCompiler
.
compilers
[
0
],
multiCompiler
.
compilers
[
1
])
// This plugin watches for changes to _document.js and notifies the client side that it should reload the page
// This plugin watches for changes to _document.js and notifies the client side that it should reload the page
multiCompiler
.
compilers
[
1
].
hooks
.
failed
.
tap
(
'NextjsHotReloaderForServer'
,
(
err
:
Error
)
=>
{
this
.
serverError
=
err
this
.
serverStats
=
null
}
)
multiCompiler
.
compilers
[
1
].
hooks
.
done
.
tap
(
multiCompiler
.
compilers
[
1
].
hooks
.
done
.
tap
(
'NextjsHotReloaderForServer'
,
'NextjsHotReloaderForServer'
,
(
stats
)
=>
{
(
stats
)
=>
{
this
.
serverError
=
null
this
.
serverStats
=
stats
this
.
serverStats
=
stats
const
{
compilation
}
=
stats
const
{
compilation
}
=
stats
...
@@ -384,9 +394,19 @@ export default class HotReloader {
...
@@ -384,9 +394,19 @@ export default class HotReloader {
}
}
)
)
multiCompiler
.
compilers
[
0
].
hooks
.
failed
.
tap
(
'NextjsHotReloaderForClient'
,
(
err
:
Error
)
=>
{
this
.
clientError
=
err
this
.
stats
=
null
}
)
multiCompiler
.
compilers
[
0
].
hooks
.
done
.
tap
(
multiCompiler
.
compilers
[
0
].
hooks
.
done
.
tap
(
'NextjsHotReloaderForClient'
,
'NextjsHotReloaderForClient'
,
(
stats
)
=>
{
(
stats
)
=>
{
this
.
clientError
=
null
this
.
stats
=
stats
const
{
compilation
}
=
stats
const
{
compilation
}
=
stats
const
chunkNames
=
new
Set
(
const
chunkNames
=
new
Set
(
compilation
.
chunks
compilation
.
chunks
...
@@ -415,7 +435,6 @@ export default class HotReloader {
...
@@ -415,7 +435,6 @@ export default class HotReloader {
}
}
}
}
this
.
stats
=
stats
this
.
prevChunkNames
=
chunkNames
this
.
prevChunkNames
=
chunkNames
}
}
)
)
...
@@ -471,7 +490,9 @@ export default class HotReloader {
...
@@ -471,7 +490,9 @@ export default class HotReloader {
public
async
getCompilationErrors
(
page
:
string
)
{
public
async
getCompilationErrors
(
page
:
string
)
{
const
normalizedPage
=
normalizePathSep
(
page
)
const
normalizedPage
=
normalizePathSep
(
page
)
if
(
this
.
stats
.
hasErrors
())
{
if
(
this
.
clientError
||
this
.
serverError
)
{
return
[
this
.
clientError
||
this
.
serverError
]
}
else
if
(
this
.
stats
?.
hasErrors
())
{
const
{
compilation
}
=
this
.
stats
const
{
compilation
}
=
this
.
stats
const
failedPages
=
erroredPages
(
compilation
)
const
failedPages
=
erroredPages
(
compilation
)
...
@@ -499,6 +520,9 @@ export default class HotReloader {
...
@@ -499,6 +520,9 @@ export default class HotReloader {
if
(
page
!==
'/_error'
&&
BLOCKED_PAGES
.
indexOf
(
page
)
!==
-
1
)
{
if
(
page
!==
'/_error'
&&
BLOCKED_PAGES
.
indexOf
(
page
)
!==
-
1
)
{
return
return
}
}
if
(
this
.
serverError
||
this
.
clientError
)
{
return
Promise
.
reject
(
this
.
serverError
||
this
.
clientError
)
}
return
this
.
onDemandEntries
.
ensurePage
(
page
)
return
this
.
onDemandEntries
.
ensurePage
(
page
)
}
}
}
}
...
...
packages/react-dev-overlay/src/middleware.ts
View file @
cac35c38
...
@@ -16,8 +16,8 @@ import { launchEditor } from './internal/helpers/launchEditor'
...
@@ -16,8 +16,8 @@ import { launchEditor } from './internal/helpers/launchEditor'
export
type
OverlayMiddlewareOptions
=
{
export
type
OverlayMiddlewareOptions
=
{
rootDirectory
:
string
rootDirectory
:
string
stats
():
webpack
.
Stats
stats
():
webpack
.
Stats
|
null
serverStats
():
webpack
.
Stats
serverStats
():
webpack
.
Stats
|
null
}
}
export
type
OriginalStackFrameResponse
=
{
export
type
OriginalStackFrameResponse
=
{
...
...
test/integration/broken-webpack-plugin/next.config.js
0 → 100644
View file @
cac35c38
class
BrokenPlugin
{
apply
(
compiler
)
{
compiler
.
hooks
.
watchRun
.
tapPromise
(
'BrokenPlugin'
,
async
()
=>
{
throw
new
Error
(
'oops'
)
})
}
}
module
.
exports
=
{
webpack
(
config
,
{
isServer
})
{
if
(
!
isServer
)
{
config
.
plugins
.
push
(
new
BrokenPlugin
())
}
return
config
},
}
test/integration/broken-webpack-plugin/pages/index.js
0 → 100644
View file @
cac35c38
export
default
function
Test
()
{
return
<
p
>
hello
from
index
<
/p
>
}
test/integration/broken-webpack-plugin/test/index.test.js
0 → 100644
View file @
cac35c38
/* eslint-env jest */
import
{
findPort
,
killApp
,
launchApp
,
renderViaHTTP
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
waitPort
from
'wait-port'
jest
.
setTimeout
(
1000
*
60
*
2
)
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
let
app
describe
(
'Handles a broken webpack plugin (precompile)'
,
()
=>
{
let
stderr
=
''
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
,
{
stderr
:
true
,
nextStart
:
true
,
onStderr
(
text
)
{
stderr
+=
text
},
})
await
waitPort
({
host
:
'localhost'
,
port
:
appPort
,
})
})
afterAll
(()
=>
killApp
(
app
))
beforeEach
(()
=>
{
stderr
=
''
})
it
(
'should render error correctly'
,
async
()
=>
{
const
text
=
await
renderViaHTTP
(
appPort
,
'/'
)
expect
(
text
).
toContain
(
'Internal Server Error'
)
expect
(
stderr
).
toMatch
(
'Error: oops'
)
})
})
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