Skip to content

Reader does not work on dynamic routes for Next JS on Vercel #949

@unkleho

Description

@unkleho

I'm trying Keystatic out for a new project and followed the Next JS tutorial. Not sure if this is a Vercel or Keystatic issue, but the reader doesn't return posts when deployed on Vercel when the page is a dynamic route (eg. [slug].tsx). Static routes work fine. Also everything works well locally.

// app/posts/[slug].tsx

const reader = createReader(process.cwd(), keystaticConfig);

export default async function PostPage(params) {
  const post = await reader.collections.posts.read(params.slug);
  // post is empty when deployed on Vercel!
  // but works fine locally

  return ...
}

Static page routes work fine:

// app/posts/static-post.tsx

const reader = createReader(process.cwd(), keystaticConfig);

export default async function PostPage() {
  const post = await reader.collections.posts.read('static-post')
  // No probs, post has data

  return ...
}

Using:

 "@keystatic/core": "^0.3.17"
 "@keystatic/next": "^3.0.0"
 "next": "14.1.0"

I've created a reproduction repo here: https://github.com/unkleho/nextjs-keystatic-test

The deployed site is here: https://nextjs-keystatic-test.vercel.app/

Any help on this would be great. Perhaps I've missed a step?
Thanks heaps for the cool project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions