Next.js: Preview mode breaking datocms-next-js-blog-demo

Created on 14 Jul 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Unhandled Runtime Error
Error: Failed to load static props

When navigating to blog post routes the following error is shown:

Error

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Setup repo as per readme
  2. Navigate to blog post eg. http://localhost:3000/posts/mistakes-tourists-make-on-their-first-trip-abroad

Expected behavior

Show blog page without error

System information

  • OS: macOS
  • Version of Next.js: 9.4.4
  • Version of Node.js: 12.18.1

Additional context

If I comment out preview here it fixes the issue but can't use Preview Mode:

export async function getStaticProps({ params, preview }) {
  const data = await getPostAndMorePosts(params.slug, preview);
  const content = await markdownToHtml(data?.post?.content || "");

  return {
    props: {
      // preview,
      post: {
        ...data?.post,
        content,
      },
      morePosts: data?.morePosts,
    },
  };
}
good first issue bug

Most helpful comment

Closing as we confirmed the latest version of this example correctly sets the default preview value. Please ensure you have the latest version of the template.

image

All 3 comments

@jahlherapath, use the default null value:

export async function getStaticProps({ params, preview = null }) {
  // ...
}

Closing as we confirmed the latest version of this example correctly sets the default preview value. Please ensure you have the latest version of the template.

image

@Timer btw, it is possible to add in the future a default value (null or false) of preview in the next.js core?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havefive picture havefive  路  3Comments

renatorib picture renatorib  路  3Comments

pie6k picture pie6k  路  3Comments

irrigator picture irrigator  路  3Comments

swrdfish picture swrdfish  路  3Comments