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
fd95d6c8
Unverified
Commit
fd95d6c8
authored
Dec 16, 2019
by
JJ Kasper
Committed by
GitHub
Dec 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix AMP HMR for child components (#9736)
parent
87d9b2e0
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
11 deletions
+44
-11
next-page-config.ts
packages/next/build/babel/plugins/next-page-config.ts
+11
-1
next-babel-loader.js
packages/next/build/webpack/loaders/next-babel-loader.js
+1
-0
hot-reloader.ts
packages/next/server/hot-reloader.ts
+4
-10
hello.js
test/integration/amphtml/components/hello.js
+1
-0
comp.js
test/integration/amphtml/pages/hmr/comp.js
+10
-0
index.test.js
test/integration/amphtml/test/index.test.js
+17
-0
No files found.
packages/next/build/babel/plugins/next-page-config.ts
View file @
fd95d6c8
...
@@ -81,7 +81,17 @@ export default function nextPageConfig({
...
@@ -81,7 +81,17 @@ export default function nextPageConfig({
}
}
if
(
config
.
amp
===
true
)
{
if
(
config
.
amp
===
true
)
{
if
(
!
(
state
.
file
&&
state
.
file
.
opts
&&
state
.
file
.
opts
.
caller
.
isDev
)
)
{
// don't replace bundle in development so HMR can track
// dependencies and trigger reload when they are changed
replaceBundle
(
path
,
t
)
replaceBundle
(
path
,
t
)
}
state
.
bundleDropped
=
true
state
.
bundleDropped
=
true
return
return
}
}
...
...
packages/next/build/webpack/loaders/next-babel-loader.js
View file @
fd95d6c8
...
@@ -130,6 +130,7 @@ module.exports = babelLoader.custom(babel => {
...
@@ -130,6 +130,7 @@ module.exports = babelLoader.custom(babel => {
options
.
caller
.
isServer
=
isServer
options
.
caller
.
isServer
=
isServer
options
.
caller
.
isModern
=
isModern
options
.
caller
.
isModern
=
isModern
options
.
caller
.
isDev
=
development
options
.
plugins
=
options
.
plugins
||
[]
options
.
plugins
=
options
.
plugins
||
[]
...
...
packages/next/server/hot-reloader.ts
View file @
fd95d6c8
import
fs
from
'fs'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
{
join
,
normalize
,
relative
as
relativePath
,
sep
}
from
'path'
import
{
join
,
normalize
,
relative
as
relativePath
,
sep
}
from
'path'
import
{
promisify
}
from
'util'
import
webpack
from
'webpack'
import
webpack
from
'webpack'
import
WebpackDevMiddleware
from
'webpack-dev-middleware'
import
WebpackDevMiddleware
from
'webpack-dev-middleware'
import
WebpackHotMiddleware
from
'webpack-hot-middleware'
import
WebpackHotMiddleware
from
'webpack-hot-middleware'
...
@@ -25,9 +23,6 @@ import onDemandEntryHandler, { normalizePage } from './on-demand-entry-handler'
...
@@ -25,9 +23,6 @@ import onDemandEntryHandler, { normalizePage } from './on-demand-entry-handler'
import
{
NextHandleFunction
}
from
'connect'
import
{
NextHandleFunction
}
from
'connect'
import
{
UrlObject
}
from
'url'
import
{
UrlObject
}
from
'url'
const
access
=
promisify
(
fs
.
access
)
const
readFile
=
promisify
(
fs
.
readFile
)
export
async
function
renderScriptError
(
res
:
ServerResponse
,
error
:
Error
)
{
export
async
function
renderScriptError
(
res
:
ServerResponse
,
error
:
Error
)
{
// Asks CDNs and others to not to cache the errored page
// Asks CDNs and others to not to cache the errored page
res
.
setHeader
(
res
.
setHeader
(
...
@@ -196,15 +191,14 @@ export default class HotReloader {
...
@@ -196,15 +191,14 @@ export default class HotReloader {
const
bundlePath
=
join
(
const
bundlePath
=
join
(
this
.
dir
,
this
.
dir
,
this
.
config
.
distDir
,
this
.
config
.
distDir
,
'static/development/pages'
,
's
erver/s
tatic/development/pages'
,
page
+
'.js'
page
+
'.js'
)
)
//
make sure to 404 for AMP bundles in case they weren't removed
//
Make sure to 404 for AMP first pages
try
{
try
{
await
access
(
bundlePath
)
const
mod
=
require
(
bundlePath
)
const
data
=
await
readFile
(
bundlePath
,
'utf8'
)
if
(
mod
&&
mod
.
config
&&
mod
.
config
.
amp
===
true
)
{
if
(
data
.
includes
(
'__NEXT_DROP_CLIENT_FILE__'
))
{
res
.
statusCode
=
404
res
.
statusCode
=
404
res
.
end
()
res
.
end
()
return
{
finished
:
true
}
return
{
finished
:
true
}
...
...
test/integration/amphtml/components/hello.js
0 → 100644
View file @
fd95d6c8
export
default
()
=>
<
p
id
=
"hello-comp"
>
hello
<
/p
>
test/integration/amphtml/pages/hmr/comp.js
0 → 100644
View file @
fd95d6c8
import
Hello
from
'../../components/hello'
export
const
config
=
{
amp
:
true
}
export
default
()
=>
(
<>
<
Hello
/>
<
span
>
{
new
Date
().
getTime
()}
<
/span
>
<
/
>
)
test/integration/amphtml/test/index.test.js
View file @
fd95d6c8
...
@@ -356,6 +356,23 @@ describe('AMP Usage', () => {
...
@@ -356,6 +356,23 @@ describe('AMP Usage', () => {
}
}
})
})
it
(
'should detect changes to component and refresh an AMP page'
,
async
()
=>
{
const
browser
=
await
webdriver
(
dynamicAppPort
,
'/hmr/comp'
)
const
text
=
await
browser
.
elementByCss
(
'#hello-comp'
).
text
()
expect
(
text
).
toBe
(
'hello'
)
const
testComp
=
join
(
__dirname
,
'../components/hello.js'
)
const
origContent
=
readFileSync
(
testComp
,
'utf8'
)
const
newContent
=
origContent
.
replace
(
'>hello<'
,
'>hi<'
)
writeFileSync
(
testComp
,
newContent
,
'utf8'
)
await
check
(()
=>
browser
.
elementByCss
(
'#hello-comp'
).
text
(),
/hi/
)
writeFileSync
(
testComp
,
origContent
,
'utf8'
)
await
check
(()
=>
browser
.
elementByCss
(
'#hello-comp'
).
text
(),
/hello/
)
})
it
(
'should not reload unless the page is edited for an AMP page'
,
async
()
=>
{
it
(
'should not reload unless the page is edited for an AMP page'
,
async
()
=>
{
let
browser
let
browser
try
{
try
{
...
...
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