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

AMP hybrid mode is missing required dynamic route query pameters #17245

Closed
lfades opened this issue Sep 20, 2020 · 13 comments · Fixed by #17461
Closed

AMP hybrid mode is missing required dynamic route query pameters #17245

lfades opened this issue Sep 20, 2020 · 13 comments · Fixed by #17461
Labels
good first issue Easy to fix issues, good for newcomers type: next

Comments

@lfades
Copy link
Member

lfades commented Sep 20, 2020

Bug report

Describe the bug

When using a dynamic route with getStaticProps and getStaticPaths, getStaticProps executes twice for every defined path but it's missing the query parameter for the AMP version. This only happens with next build

E.g if getStaticPaths returns /hello-world for [slug].js then getStaticProps gets executed twice with the following context:

{ params: { slug: 'hello-world' } }
{ params: { amp: '1' } }

Expected behavior

The AMP version should have the required query parameters for the dynamic route.

Additional context

Using Next.js 9.5.4-canary.20- Happened with both webpack 4 and webpack 5

@lfades lfades added kind: bug type: next good first issue Easy to fix issues, good for newcomers labels Sep 20, 2020
@ayshiff
Copy link

ayshiff commented Sep 21, 2020

Can I work on it @lfades ? 👍

@lfades
Copy link
Member Author

lfades commented Sep 21, 2020

@ayshiff Sure 👍

@ayshiff
Copy link

ayshiff commented Sep 22, 2020

I am a little bit struggling reproducing the bug.
For me the getStaticProps is executed once with the following context: { params: { slug: 'hello-world', amp: '1' } }
Could you give me a way to reproduce your behavior ?

@lfades
Copy link
Member Author

lfades commented Sep 22, 2020

@ayshiff Are you running Next.js on the latest canary and using AMP in hybrid mode?

@ayshiff
Copy link

ayshiff commented Sep 22, 2020

I am using Next.js 9.5.4-canary.20 and I am also using AMP in hybrid mode 👍
I tested on the /examples/blog-starter project by enabling AMP inside /pages/posts/[slug].js.

@lfades
Copy link
Member Author

lfades commented Sep 22, 2020

@ayshiff Oh one last thing, this only happens when you run next build 😅

@ayshiff
Copy link

ayshiff commented Sep 22, 2020

After running next build, for the Generating static pages part, getStaticProps gets executed twice with:

{ params: { slug: 'hello-world' } }
{ params: { slug: 'hello-world', amp: '1' } }

I'll try to show you the code I'm using and the corresponding output to try to understand why I don't have the same behavior as you 👍

@lfades
Copy link
Member Author

lfades commented Sep 22, 2020

@ayshiff In that case you don't have spend more time on this 👍 . I'll see If I can reproduce it again later.

@ayshiff
Copy link

ayshiff commented Sep 22, 2020

No problem ! I will try to take another issue then 👍

@cjimmy
Copy link
Contributor

cjimmy commented Oct 13, 2020

I'm seeing this same issue on 9.5.5, but only on vercel. When I run the build locally (next build), and log the params from getStaticPaths() I correctly get the correct set of props into getStaticProps

{ params: { pid: 'prop-17' }, locales: undefined, locale: undefined }
{ params: { pid: 'prop-17', amp: 1 }, locales: undefined ,locale: undefined}

but when I run this on vercel (vercel), this is what getStaticProps receives:

{ params: { pid: 'prop-15' }, locales: undefined, locale: undefined }
{ params: { amp: '1' }, locales: undefined, locale: undefined }

I don't know if I can make a repro easily, but maybe this helps point to the problem. Why would this happen on vercel but not locally?

@slawekkolodziej
Copy link
Contributor

I created a PR that fixes this: #17461

@slawekkolodziej
Copy link
Contributor

For what it's worth, this happened when I run next build in a project with target: 'serverless'.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers type: next
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants