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
fdfbab5d
Commit
fdfbab5d
authored
Apr 16, 2019
by
JJ Kasper
Committed by
Connor Davis
Apr 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated handling of AMP page reloading (#7052)
parent
abae1734
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
219 additions
and
1 deletion
+219
-1
amp-dev.js
packages/next/client/amp-dev.js
+6
-1
amp.js
test/integration/amphtml/pages/hmr/amp.js
+8
-0
hybrid.js
test/integration/amphtml/pages/hmr/hybrid.js
+5
-0
root-hmr.js
test/integration/amphtml/pages/root-hmr.js
+5
-0
index.test.js
test/integration/amphtml/test/index.test.js
+195
-0
No files found.
packages/next/client/amp-dev.js
View file @
fdfbab5d
...
@@ -40,7 +40,12 @@ async function tryApplyUpdates () {
...
@@ -40,7 +40,12 @@ async function tryApplyUpdates () {
const
data
=
await
res
.
json
()
const
data
=
await
res
.
json
()
const
curPage
=
page
===
'/'
?
'index'
:
page
const
curPage
=
page
===
'/'
?
'index'
:
page
const
pageUpdated
=
Object
.
keys
(
data
.
c
)
const
pageUpdated
=
Object
.
keys
(
data
.
c
)
.
some
(
mod
=>
mod
.
indexOf
(
`pages/
${
curPage
}
`
)
!==
-
1
)
.
some
(
mod
=>
{
return
(
mod
.
indexOf
(
`pages
${
curPage
.
substr
(
0
,
1
)
===
'/'
?
curPage
:
`/
${
curPage
}
`
}
`
)
!==
-
1
||
mod
.
indexOf
(
`pages
${
curPage
.
substr
(
0
,
1
)
===
'/'
?
curPage
:
`/
${
curPage
}
`
}
`
.
replace
(
/
\/
/g
,
'
\
\'
)) !== -1
)
})
if (pageUpdated) {
if (pageUpdated) {
document.location.reload(true)
document.location.reload(true)
...
...
test/integration/amphtml/pages/hmr/amp.js
0 → 100644
View file @
fdfbab5d
import
{
withAmp
}
from
'next/amp'
export
default
withAmp
(()
=>
(
<>
<
p
>
I
'm an AMP page!</p>
<span>{new Date().getTime()}</span>
</>
))
test/integration/amphtml/pages/hmr/hybrid.js
0 → 100644
View file @
fdfbab5d
import
{
withAmp
}
from
'next/amp'
export
default
withAmp
(()
=>
(
<
p
>
I
'm a hybrid AMP page!</p>
), { hybrid: true })
test/integration/amphtml/pages/root-hmr.js
0 → 100644
View file @
fdfbab5d
import
{
withAmp
}
from
'next/amp'
export
default
withAmp
(()
=>
(
<
p
>
I
'm an AMP page!</p>
))
test/integration/amphtml/test/index.test.js
View file @
fdfbab5d
...
@@ -6,6 +6,7 @@ import webdriver from 'next-webdriver'
...
@@ -6,6 +6,7 @@ import webdriver from 'next-webdriver'
import
{
validateAMP
}
from
'amp-test-utils'
import
{
validateAMP
}
from
'amp-test-utils'
import
{
readFileSync
,
writeFileSync
}
from
'fs'
import
{
readFileSync
,
writeFileSync
}
from
'fs'
import
{
import
{
waitFor
,
nextServer
,
nextServer
,
nextBuild
,
nextBuild
,
startApp
,
startApp
,
...
@@ -245,11 +246,14 @@ describe('AMP Usage', () => {
...
@@ -245,11 +246,14 @@ describe('AMP Usage', () => {
describe
(
'editing a page'
,
()
=>
{
describe
(
'editing a page'
,
()
=>
{
let
dynamicAppPort
let
dynamicAppPort
let
ampDynamic
let
ampDynamic
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
dynamicAppPort
=
await
findPort
()
dynamicAppPort
=
await
findPort
()
ampDynamic
=
await
launchApp
(
join
(
__dirname
,
'../'
),
dynamicAppPort
)
ampDynamic
=
await
launchApp
(
join
(
__dirname
,
'../'
),
dynamicAppPort
)
})
})
afterAll
(()
=>
killApp
(
ampDynamic
))
afterAll
(()
=>
killApp
(
ampDynamic
))
it
(
'should detect the changes and display it'
,
async
()
=>
{
it
(
'should detect the changes and display it'
,
async
()
=>
{
let
browser
let
browser
try
{
try
{
...
@@ -290,5 +294,196 @@ describe('AMP Usage', () => {
...
@@ -290,5 +294,196 @@ describe('AMP Usage', () => {
await
browser
.
close
()
await
browser
.
close
()
}
}
})
})
it
(
'should detect changes and refresh an AMP page'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
dynamicAppPort
,
'/hmr/amp'
)
const
text
=
await
browser
.
elementByCss
(
'p'
).
text
()
expect
(
text
).
toBe
(
`I'm an AMP page!`
)
const
hmrTestPagePath
=
join
(
__dirname
,
'../'
,
'pages'
,
'hmr'
,
'amp.js'
)
const
originalContent
=
readFileSync
(
hmrTestPagePath
,
'utf8'
)
const
editedContent
=
originalContent
.
replace
(
`I'm an AMP page!`
,
'replaced it!'
)
// change the content
writeFileSync
(
hmrTestPagePath
,
editedContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/replaced it!/
)
// add the original content
writeFileSync
(
hmrTestPagePath
,
originalContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/I'm an AMP page!/
)
}
finally
{
await
browser
.
close
()
}
})
it
(
'should not reload unless the page is edited for an AMP page'
,
async
()
=>
{
let
browser
try
{
await
renderViaHTTP
(
dynamicAppPort
,
'/hmr/test'
)
browser
=
await
webdriver
(
dynamicAppPort
,
'/hmr/amp'
)
const
text
=
await
browser
.
elementByCss
(
'p'
).
text
()
const
origDate
=
await
browser
.
elementByCss
(
'span'
).
text
()
expect
(
text
).
toBe
(
`I'm an AMP page!`
)
const
hmrTestPagePath
=
join
(
__dirname
,
'../'
,
'pages'
,
'hmr'
,
'test.js'
)
const
originalContent
=
readFileSync
(
hmrTestPagePath
,
'utf8'
)
const
editedContent
=
originalContent
.
replace
(
`This is the hot AMP page.`
,
'replaced it!'
)
// change the content
writeFileSync
(
hmrTestPagePath
,
editedContent
,
'utf8'
)
let
checks
=
5
let
i
=
0
while
(
i
<
checks
)
{
const
curText
=
await
browser
.
elementByCss
(
'span'
).
text
()
expect
(
curText
).
toBe
(
origDate
)
await
waitFor
(
1000
)
i
++
}
// add the original content
writeFileSync
(
hmrTestPagePath
,
originalContent
,
'utf8'
)
const
otherHmrTestPage
=
join
(
__dirname
,
'../pages/hmr/amp.js'
)
const
otherOrigContent
=
readFileSync
(
otherHmrTestPage
,
'utf8'
)
const
otherEditedContent
=
otherOrigContent
.
replace
(
`I'm an AMP page!`
,
`replaced it!`
)
// change the content
writeFileSync
(
otherHmrTestPage
,
otherEditedContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/replaced it!/
)
// restore original content
writeFileSync
(
otherHmrTestPage
,
otherOrigContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/I'm an AMP page!/
)
}
finally
{
await
browser
.
close
()
}
})
it
(
'should detect changes and refresh a hybrid AMP page'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
dynamicAppPort
,
'/hmr/hybrid?amp=1'
)
const
text
=
await
browser
.
elementByCss
(
'p'
).
text
()
expect
(
text
).
toBe
(
`I'm a hybrid AMP page!`
)
const
hmrTestPagePath
=
join
(
__dirname
,
'../'
,
'pages'
,
'hmr'
,
'hybrid.js'
)
const
originalContent
=
readFileSync
(
hmrTestPagePath
,
'utf8'
)
const
editedContent
=
originalContent
.
replace
(
`I'm a hybrid AMP page!`
,
'replaced it!'
)
// change the content
writeFileSync
(
hmrTestPagePath
,
editedContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/replaced it!/
)
// add the original content
writeFileSync
(
hmrTestPagePath
,
originalContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/I'm a hybrid AMP page!/
)
}
finally
{
await
browser
.
close
()
}
})
it
(
'should detect changes and refresh an AMP page at root pages/'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
dynamicAppPort
,
'/root-hmr'
)
const
text
=
await
browser
.
elementByCss
(
'p'
).
text
()
expect
(
text
).
toBe
(
`I'm an AMP page!`
)
const
hmrTestPagePath
=
join
(
__dirname
,
'../'
,
'pages'
,
'root-hmr.js'
)
const
originalContent
=
readFileSync
(
hmrTestPagePath
,
'utf8'
)
const
editedContent
=
originalContent
.
replace
(
`I'm an AMP page!`
,
'replaced it!'
)
// change the content
writeFileSync
(
hmrTestPagePath
,
editedContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/replaced it!/
)
// add the original content
writeFileSync
(
hmrTestPagePath
,
originalContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/I'm an AMP page!/
)
}
finally
{
await
browser
.
close
()
}
})
})
})
})
})
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