Skip to content

Commit 4238878

Browse files
slawekkolodziejtimneutkenskodiakhq[bot]
authored
Make sure that params are properly passed to hybrid amp pages (#17461)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent ee0a4a7 commit 4238878

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/next/export/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ export default async function exportPage({
352352
if (serverless) {
353353
req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'
354354
// @ts-ignore
355-
ampHtml = (await renderMethod(req, res, 'export')).html
355+
ampHtml = (await renderMethod(req, res, 'export', undefined, params))
356+
.html
356357
} else {
357358
ampHtml = await renderMethod(
358359
req,

test/integration/amphtml-ssg/pages/blog/[slug].js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export const config = {
44
amp: 'hybrid',
55
}
66

7-
export const getStaticProps = () => {
7+
export const getStaticProps = (ctx) => {
88
return {
99
props: {
10+
slug: ctx.params?.slug || null,
1011
hello: 'hello',
1112
random: Math.random(),
1213
},
@@ -18,10 +19,11 @@ export const getStaticPaths = () => ({
1819
fallback: false,
1920
})
2021

21-
export default ({ hello, random }) => (
22+
export default ({ hello, random, slug }) => (
2223
<>
2324
<p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p>
2425
<p id="hello">{hello}</p>
2526
<p id="random">{random}</p>
27+
<p id="slug">{slug}</p>
2628
</>
2729
)

test/integration/amphtml-ssg/test/index.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,23 @@ const runTests = (isDev = false) => {
5151
const $ = cheerio.load(html)
5252
expect($('#use-amp').text()).toContain('no')
5353
expect($('#hello').text()).toContain('hello')
54+
expect($('#slug').text()).toContain('post-1')
5455
})
5556

5657
it('should load dynamic hybrid SSG/AMP page with trailing slash', async () => {
5758
const html = await renderViaHTTP(appPort, '/blog/post-1/')
5859
const $ = cheerio.load(html)
5960
expect($('#use-amp').text()).toContain('no')
6061
expect($('#hello').text()).toContain('hello')
62+
expect($('#slug').text()).toContain('post-1')
6163
})
6264

6365
it('should load dynamic hybrid SSG/AMP page with query', async () => {
6466
const html = await renderViaHTTP(appPort, '/blog/post-1?amp=1')
6567
const $ = cheerio.load(html)
6668
expect($('#use-amp').text()).toContain('yes')
6769
expect($('#hello').text()).toContain('hello')
70+
expect($('#slug').text()).toContain('post-1')
6871
})
6972

7073
it('should load a hybrid amp page with query correctly', async () => {

0 commit comments

Comments
 (0)