Unverified Commit 4238878c authored by Slawek Kolodziej's avatar Slawek Kolodziej Committed by GitHub

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

Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent ee0a4a70
...@@ -352,7 +352,8 @@ export default async function exportPage({ ...@@ -352,7 +352,8 @@ export default async function exportPage({
if (serverless) { if (serverless) {
req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1' req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'
// @ts-ignore // @ts-ignore
ampHtml = (await renderMethod(req, res, 'export')).html ampHtml = (await renderMethod(req, res, 'export', undefined, params))
.html
} else { } else {
ampHtml = await renderMethod( ampHtml = await renderMethod(
req, req,
......
...@@ -4,9 +4,10 @@ export const config = { ...@@ -4,9 +4,10 @@ export const config = {
amp: 'hybrid', amp: 'hybrid',
} }
export const getStaticProps = () => { export const getStaticProps = (ctx) => {
return { return {
props: { props: {
slug: ctx.params?.slug || null,
hello: 'hello', hello: 'hello',
random: Math.random(), random: Math.random(),
}, },
...@@ -18,10 +19,11 @@ export const getStaticPaths = () => ({ ...@@ -18,10 +19,11 @@ export const getStaticPaths = () => ({
fallback: false, fallback: false,
}) })
export default ({ hello, random }) => ( export default ({ hello, random, slug }) => (
<> <>
<p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p> <p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p>
<p id="hello">{hello}</p> <p id="hello">{hello}</p>
<p id="random">{random}</p> <p id="random">{random}</p>
<p id="slug">{slug}</p>
</> </>
) )
...@@ -51,6 +51,7 @@ const runTests = (isDev = false) => { ...@@ -51,6 +51,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no') expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello') expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
}) })
it('should load dynamic hybrid SSG/AMP page with trailing slash', async () => { it('should load dynamic hybrid SSG/AMP page with trailing slash', async () => {
...@@ -58,6 +59,7 @@ const runTests = (isDev = false) => { ...@@ -58,6 +59,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no') expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello') expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
}) })
it('should load dynamic hybrid SSG/AMP page with query', async () => { it('should load dynamic hybrid SSG/AMP page with query', async () => {
...@@ -65,6 +67,7 @@ const runTests = (isDev = false) => { ...@@ -65,6 +67,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('yes') expect($('#use-amp').text()).toContain('yes')
expect($('#hello').text()).toContain('hello') expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
}) })
it('should load a hybrid amp page with query correctly', async () => { it('should load a hybrid amp page with query correctly', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment