vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.86k stars 26.97k forks source link

Server Side Exception during Production while implementing pagination and reading from search params. Application error: a server-side exception has occurred (see the server logs for more information). Digest: 163034583 #66596

Open Rahulg321 opened 5 months ago

Rahulg321 commented 5 months ago

Link to the code that reproduces this issue

https://github.com/Rahulg321/Law-Offices-of-Destiny-Aigbe

To Reproduce

You can go to my code and start the application in dev mode and visit the blogs section. I am fetching my data using Prismic CMS and reading from search params so as to implement Pagination. The entire work flow works well in development mode but breaks during production when the side is deployed

These are the error logs I am receiving during production

[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] { digest: '163034583' }

F [Error]: Ref not found. Ensure you have the correct ref and try again. Master ref is: ZmCkDxEAAB4AxJSv
    at N.fetch (/var/task/.next/server/chunks/5367.js:1:12841)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async N.get (/var/task/.next/server/chunks/5367.js:1:5911)
    at async N.getByType (/var/task/.next/server/chunks/5367.js:1:7144)
    at async m (/var/task/.next/server/app/blogs/page.js:1:7240) {
  url: 'https://aigbelaw.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bat%28document.type%2C+%22blogpost%22%29%5D%5D&page=1&pageSize=20&ref=Zl8-nBEAACAAwmIG&routes=%5B%7B%22type%22%3A%22homepage%22%2C%22path%22%3A%22%2F%22%7D%2C%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid%22%7D%5D',
  response: {
    type: 'api_notfound_error',
    message: 'Ref not found. Ensure you have the correct ref and try again. Master ref is: ZmCkDxEAAB4AxJSv'
  }
}

Current vs. Expected behavior

The pagination works perfectly fine on development mode but breaks during production. I have included the error logs and full code details. I figure its due to the fact that I am using a mix of ssr and dynamic rendering.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home Single Language
Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure, Output (export/standalone)

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

This is the code I am using. I am thinking the error is in the way createClient is initialized using Prismic and how catching is configured there.

This is how createClient is initialized from Prismic

import * as prismic from "@prismicio/client";
import * as prismicNext from "@prismicio/next";
import config from "./slicemachine.config.json";

/**
 * The project's Prismic repository name.
 */
export const repositoryName =
  process.env.NEXT_PUBLIC_PRISMIC_ENVIRONMENT || config.repositoryName;

/**
 * A list of Route Resolver objects that define how a document's `url` field is resolved.
 *
 * {@link https://prismic.io/docs/route-resolver#route-resolver}
 */
// TODO: Update the routes array to match your project's route structure.
const routes: prismic.ClientConfig["routes"] = [
  // Examples:
  {
    type: "homepage",
    path: "/",
  },

  {
    type: "page",
    path: "/:uid",
  },
];

/**
 * Creates a Prismic client for the project's repository. The client is used to
 * query content from the Prismic API.
 *
 * @param config - Configuration for the Prismic client.
 */
export const createClient = (config: prismicNext.CreateClientConfig = {}) => {
  const client = prismic.createClient(repositoryName, {
    routes,
    fetchOptions:
      process.env.NODE_ENV === "production"
        ? { next: { tags: ["prismic"] }, cache: "force-cache" }
        : { next: { revalidate: 5 } },
    ...config,
  });

  prismicNext.enableAutoPreviews({
    client,
    previewData: config.previewData,
    req: config.req,
  });

  return client;
};

Screenshot (195) Screenshot (196) Screenshot (197) Screenshot (198) Screenshot (199) Screenshot (200)

JedBh commented 5 months ago

hey @Rahulg321 if you can try and delete your project from Vercel and redeploy it to Vercel. The issue is some cache error that pops up and I found that the best workaround for me is initiating the project from scratch. Hope it works for you too.