Skip to content

SSG with fallback doesn't generate AMP page dynamically #14256

Open
@wawoon

Description

@wawoon

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

Metadata

Metadata

Assignees

Labels

Pages RouterRelated to Pages Router.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions