API 500 "Unexpected Error" in Preview Mode with Repeatable Link Field

Description of the Issue:

In preview mode, the Prismic API returns an HTTP 500 error with the message { type: 'api_internal_error', message: 'Unexpected error' } for certain requests, resulting in a client-side error: [Server] Error: An invalid API response was returned

This blocks page rendering, including pages unrelated to the affected field.

To debug, I customized the Prismic client to log API responses:

export const createClient = (config: prismic.ClientConfig = {}) => {
  const client = prismic.createClient(repositoryName, {
    routes,
    fetchOptions:
      process.env.NODE_ENV === "production"
        ? { next: { tags: ["prismic"] }, cache: "force-cache" }
        : { next: { revalidate: 5 } },
    fetch: async (url, options) => {
      const response = await fetch(url, options);
      try {
        const json = await response.clone().json();
        console.log(`Prismic API Request: ${url}`, {
          status: response.status,
          response: json,
        });
      } catch (error) {
        console.error(`Failed to parse Prismic API response for ${url}`, error);
      }
      return response;
    },
    ...config,
  });

  prismicNext.enableAutoPreviews({ client });

  return client;
};

The logs reveal the API error:

Prismic API Request: https://prismic-testing-demo-second.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bat%28document.type%2C+%22page%22%29%5D%5D&q=%5B%5Bat%28my.page.uid%2C+%22test-again%22%29%5D%5D&pageSize=1&ref=...
status: 500,
response: { type: 'api_internal_error', message: 'Unexpected error' }

Problem Details:

  • The issue occurs only when editing a repeatable Link field in the static zone of a page document.
  • The error does not occur when:
    • Modifying a non-repeatable Link field.
    • Modifying any other field in the static zone.
    • Modifying a repeatable Link field inside a slice (outside the static zone).
  • Once the repeatable Link field is edited (even if emptied afterward), the API error persists, and relaunching the preview from Prismic Studio results in a browser HTTP 500 error page.
  • The preview cookies (io.prismic.preview) are correctly set, but the API error prevents rendering.

Environment:

  • Repository: prismic-testing-demo-second
  • Packages:
    • @prismicio/client: ^7.15.1
    • @prismicio/next: ^2.0.0
    • @prismicio/react: ^3.0.0
  • Framework: Next.js 15.1.6 (App Router)
  • Environment: Local development (npm run dev)

Request:

Can you investigate the cause of the api_internal_error in preview mode, specifically related to repeatable Link fields in the static zone? If this is due to residual metadata in the links field, is there a way to clear it or prevent this issue?

Thank you for your assistance!

Hi @tanguy.freycon,

Welcome to the community! Thank you for the detailed issue report - I've tried to recreate this issue and haven't had much luck. Could you record a Jam of this error, trying to open the preview that's not working? If you don't want to share it here, you can send it to me via DM. It'll help us investigate this further :slight_smile:

Thanks for your help!