Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that params are properly passed to hybrid amp pages #17461

Merged
merged 9 commits into from Oct 15, 2020
3 changes: 2 additions & 1 deletion packages/next/export/worker.ts
Expand Up @@ -352,7 +352,8 @@ export default async function exportPage({
if (serverless) {
req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'
// @ts-ignore
ampHtml = (await renderMethod(req, res, 'export')).html
ampHtml = (await renderMethod(req, res, 'export', undefined, params))
Copy link
Member

@ijjk ijjk Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fourth parameter here should match this line, this can be updated in a follow-up PR as it addresses different cases. Good catch!

PR updating this here #17923

.html
} else {
ampHtml = await renderMethod(
req,
Expand Down
6 changes: 4 additions & 2 deletions test/integration/amphtml-ssg/pages/blog/[slug].js
Expand Up @@ -4,9 +4,10 @@ export const config = {
amp: 'hybrid',
}

export const getStaticProps = () => {
export const getStaticProps = (ctx) => {
return {
props: {
slug: ctx.params?.slug || null,
hello: 'hello',
random: Math.random(),
},
Expand All @@ -18,10 +19,11 @@ export const getStaticPaths = () => ({
fallback: false,
})

export default ({ hello, random }) => (
export default ({ hello, random, slug }) => (
<>
<p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p>
<p id="hello">{hello}</p>
<p id="random">{random}</p>
<p id="slug">{slug}</p>
</>
)
3 changes: 3 additions & 0 deletions test/integration/amphtml-ssg/test/index.test.js
Expand Up @@ -51,20 +51,23 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})

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

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')
expect($('#slug').text()).toContain('post-1')
})

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