Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
7f604a50
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7f604a50
编写于
5月 19, 2020
作者:
S
Slawek Kolodziej
提交者:
GitHub
5月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix building server-side generated AMP pages (#13046)
上级
dde5d3bd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
5 deletion
+75
-5
packages/next/build/index.ts
packages/next/build/index.ts
+21
-1
packages/next/export/worker.js
packages/next/export/worker.js
+8
-0
packages/next/next-server/server/next-server.ts
packages/next/next-server/server/next-server.ts
+3
-4
test/integration/amphtml-ssg/pages/blog/[slug].js
test/integration/amphtml-ssg/pages/blog/[slug].js
+27
-0
test/integration/amphtml-ssg/test/index.test.js
test/integration/amphtml-ssg/test/index.test.js
+16
-0
未找到文件。
packages/next/build/index.ts
浏览文件 @
7f604a50
...
...
@@ -838,8 +838,12 @@ export default async function build(dir: string, conf = null): Promise<void> {
await
moveExportedPage
(
page
,
file
,
isSsg
,
'
html
'
)
}
if
(
hasAmp
)
{
if
(
hasAmp
&&
(
!
isSsg
||
(
isSsg
&&
!
isDynamic
))
)
{
await
moveExportedPage
(
`
${
page
}
.amp`
,
`
${
file
}
.amp`
,
isSsg
,
'
html
'
)
if
(
isSsg
)
{
await
moveExportedPage
(
`
${
page
}
.amp`
,
`
${
file
}
.amp`
,
isSsg
,
'
json
'
)
}
}
if
(
isSsg
)
{
...
...
@@ -862,6 +866,22 @@ export default async function build(dir: string, conf = null): Promise<void> {
for
(
const
route
of
extraRoutes
)
{
await
moveExportedPage
(
route
,
route
,
true
,
'
html
'
)
await
moveExportedPage
(
route
,
route
,
true
,
'
json
'
)
if
(
hasAmp
)
{
await
moveExportedPage
(
`
${
route
}
.amp`
,
`
${
route
}
.amp`
,
true
,
'
html
'
)
await
moveExportedPage
(
`
${
route
}
.amp`
,
`
${
route
}
.amp`
,
true
,
'
json
'
)
}
finalPrerenderRoutes
[
route
]
=
{
initialRevalidateSeconds
:
exportConfig
.
initialPageRevalidationMap
[
route
],
...
...
packages/next/export/worker.js
浏览文件 @
7f604a50
...
...
@@ -269,6 +269,14 @@ export default async function ({
JSON
.
stringify
(
curRenderOpts
.
pageData
),
'
utf8
'
)
if
(
curRenderOpts
.
hybridAmp
)
{
await
promises
.
writeFile
(
dataFile
.
replace
(
/
\.
json$/
,
'
.amp.json
'
),
JSON
.
stringify
(
curRenderOpts
.
pageData
),
'
utf8
'
)
}
}
results
.
fromBuildExportRevalidate
=
curRenderOpts
.
revalidate
...
...
packages/next/next-server/server/next-server.ts
浏览文件 @
7f604a50
...
...
@@ -1025,9 +1025,7 @@ export default class Server {
}
// Compute the iSSG cache key
let
urlPathname
=
`
${
parseUrl
(
req
.
url
||
''
).
pathname
!
}${
query
.
amp
?
'
.amp
'
:
''
}
`
let
urlPathname
=
`
${
parseUrl
(
req
.
url
||
''
).
pathname
!
}
`
// remove /_next/data prefix from urlPathname so it matches
// for direct page visit and /_next/data visit
...
...
@@ -1039,10 +1037,11 @@ export default class Server {
const
ssgCacheKey
=
isPreviewMode
?
undefined
// Preview mode bypasses the cache
:
urlPathname
:
`
${
urlPathname
}${
query
.
amp
?
'
.amp
'
:
''
}
`
// Complete the response with cached data if its present
const
cachedData
=
ssgCacheKey
?
await
getSprCache
(
ssgCacheKey
)
:
undefined
if
(
cachedData
)
{
const
data
=
isDataReq
?
JSON
.
stringify
(
cachedData
.
pageData
)
...
...
test/integration/amphtml-ssg/pages/blog/[slug].js
0 → 100644
浏览文件 @
7f604a50
import
{
useAmp
}
from
'
next/amp
'
export
const
config
=
{
amp
:
'
hybrid
'
,
}
export
const
getStaticProps
=
()
=>
{
return
{
props
:
{
hello
:
'
hello
'
,
random
:
Math
.
random
(),
},
}
}
export
const
getStaticPaths
=
()
=>
({
paths
:
[
'
/blog/post-1
'
,
'
/blog/post-2
'
],
fallback
:
false
,
})
export
default
({
hello
,
random
})
=>
(
<>
<
p
id
=
"
use-amp
"
>
useAmp
:
{
useAmp
()
?
'
yes
'
:
'
no
'
}
<
/p
>
<
p
id
=
"
hello
"
>
{
hello
}
<
/p
>
<
p
id
=
"
random
"
>
{
random
}
<
/p
>
<
/
>
)
test/integration/amphtml-ssg/test/index.test.js
浏览文件 @
7f604a50
...
...
@@ -46,6 +46,20 @@ const runTests = (isDev = false) => {
expect
(
$
(
'
#hello
'
).
text
()).
toContain
(
'
hello
'
)
})
it
(
'
should load dynamic hybrid SSG/AMP page
'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'
/blog/post-1
'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'
#use-amp
'
).
text
()).
toContain
(
'
no
'
)
expect
(
$
(
'
#hello
'
).
text
()).
toContain
(
'
hello
'
)
})
it
(
'
should load dynamic hybrid SSG/AMP page with query
'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'
/blog/post-1?amp=1
'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'
#use-amp
'
).
text
()).
toContain
(
'
yes
'
)
expect
(
$
(
'
#hello
'
).
text
()).
toContain
(
'
hello
'
)
})
it
(
'
should load a hybrid amp page with query correctly
'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'
/hybrid?amp=1
'
)
...
...
@@ -139,6 +153,8 @@ describe('AMP SSG Support', () => {
expect
(
await
fsExists
(
outFile
(
'
hybrid.html
'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'
amp.amp.html
'
))).
toBe
(
false
)
expect
(
await
fsExists
(
outFile
(
'
hybrid.amp.html
'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'
blog/post-1.html
'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'
blog/post-1.amp.html
'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
join
(
'
_next/data
'
,
buildId
,
'
amp.json
'
)))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录