question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSG with fallback doesn't generate AMP page dynamically

See original GitHub issue

Bug report

Describe the bug

  • When SSG with fallback: true and amp: "hybrid" are used together, the paths not specified in getStaticPaths have an invalid href in <link rel="amphtml"> tag.
    • For example, when there is a pages/[slug].jsx and the user visits /bar, the <link rel="amphtml"> tag will refer to /[slug].amp.

To Reproduce

https://github.com/wawoon/next-amp-ssg-fallback-reproduce

pages/[slug]/index.jsx

export default (props) => {
  return <div>slug: {props.slug}</div>;
};

export const config = {
  amp: "hybrid",
};

export const getStaticProps = async (ctx) => {
  return {
    props: {
      slug: ctx.params.slug,
    },
  };
};

export const getStaticPaths = async () => {
  return { paths: [{ params: { slug: "foo" } }], fallback: true };
};

※ caution: When you add unstable_revalidate to getStaticProps, the href of <link rel="amphtml"> is overwritten while regeneration by #14251

When the user visits http://localhost:3000/bar, bar is not specified in getStaticPaths, the href of <link rel="amphtml"> refers to /[slug].amp. And this /[slug].amp is invalid url.

スクリーンショット 2020-06-17 14 21 57

Expected behavior

  • The /bar should have correct amp page path, even when the path is not included in getStaticPaths.
  • The amp version of /bar should be generated using getStaticProps dynamically.

Screenshots

System information

  • macOS
  • Chrome
  • Next: 9.4.5-canary.12
  • Node: v12.14.1

Additional context

  • I have recently created #14251 which is related with amp page with SSG.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
yassinebridicommented, Oct 27, 2020

@Timer I’m using fallback: 'blocking', with Next@10, still has the same problem, it doesn’t revalidate.

2reactions
Timercommented, Aug 10, 2020

AMP will require you use fallback: 'unstable_blocking', maybe we can toggle this by default for AMP pages!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incremental Static Regeneration - Data Fetching - Next.js
Learn how to create or update static pages at runtime with Incremental Static ... pages // on-demand if the path doesn't exist. return...
Read more >
Server Side Render Dynamic Page based on Route Param
The purpose of the function getStaticPaths is to generate a list of paths for which static HTML will be rendered at build time....
Read more >
How to Create Pages in Next.js with Static & Dynamic Data
Step 2: Using getStaticProps to statically generate a page with dynamic data. Next up is getStaticProps and statically compiling our page.
Read more >
Documentation: <amp-bind> - amp.dev
For performance, and to avoid the risk of unexpected content jumping, amp-bind does not evaluate expressions on page load. This means visual elements...
Read more >
Remix vs Next.js - Bejamas
That would mean having to generate every page at build time ... Although Remix doesn't support SSG, the Remix team suggests using HTTP ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found