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' } }
The AMP version should have the required query parameters for the dynamic route.
Using Next.js 9.5.4-canary.20- Happened with both webpack 4 and webpack 5
Can I work on it @lfades ? 馃憤
@ayshiff Sure 馃憤
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 ?
@ayshiff Are you running Next.js on the latest canary and using AMP in hybrid mode?
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.
@ayshiff Oh one last thing, this only happens when you run next build 馃槄
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 馃憤
@ayshiff In that case you don't have spend more time on this 馃憤 . I'll see If I can reproduce it again later.
No problem ! I will try to take another issue then 馃憤
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?
I created a PR that fixes this: https://github.com/vercel/next.js/pull/17461
For what it's worth, this happened when I run next build in a project with target: 'serverless'.