Skip to content

plugin-seo & ui: PreviewField throws "circular structure to JSON" #16786

Open

Description

@codeplott

Describe the Bug

On the SEO tab of a document that contains an array field with a custom RowLabel component and at least one row with a populated relationship, Payload throws:

  TypeError: Converting circular structure to JSON
      --> starting at object with constructor 'BasePayload'
      |     property 'db' -> object with constructor 'Object'
      --- property 'payload' closes the circle

It throws inside PreviewComponent's useEffect while building the body for POST /api/plugin-seo/generate-url. MetaTitleField's Auto-generate button does the same
thing against /api/plugin-seo/generate-title.

reduceToSerializableFields in @payloadcms/ui calls a shallow sanitizeField helper that strips customComponents and validate only from the top-level of each field entry. Array form state has the same keys inside rows[i], and those still hold the rendered RowLabel tree.

Link to the code that reproduces this issue

https://github.com/codeplott/payloadcms-rowlabel-plugin-seo

Reproduction Steps

Clone: https://github.com/codeplott/payloadcms-rowlabel-plugin-seo

  1. Create a page, give it a title and slug, save.
  2. Add one entry to the links array, set label, pick the page itself (or any other page) for reference, save.
  3. Reload the edit view.
  4. The runtime error overlay shows Converting circular structure to JSON ... BasePayload ... db ... payload.
  5. The SEO Preview URL stays at https://... instead of what generateURL would produce. Clicking the MetaTitle "Auto-generate" button throws the same error.

Which area(s) are affected?

plugin: seo

Environment Info

Binaries:
    Node: 24.16.0
    npm: 11.15.0
    pnpm: 10.33.4
  Relevant Packages:
    payload: 3.85.0
    next: 16.2.6
    @payloadcms/db-mongodb: 3.85.0
    @payloadcms/graphql: 3.85.0
    @payloadcms/next/utilities: 3.85.0
    @payloadcms/plugin-seo: 3.85.0
    @payloadcms/richtext-lexical: 3.85.0
    @payloadcms/translations: 3.85.0
    @payloadcms/ui/shared: 3.85.0
    react: 19.2.6
    react-dom: 19.2.6
  Operating System:
    Platform: darwin
    Arch: arm64

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on May 29, 2026
  2. added
    plugin: seo
    and removed
    validate-reproduction
    on May 29, 2026
  3. changed the title [-]plugin-seo: PreviewField throws "circular structure to JSON"[/-] [+]plugin-seo & ui: PreviewField throws "circular structure to JSON"[/+] on May 29, 2026
  4. drianoaz commented on Oct 7, 2026

    @drianoaz

    Still reproducible on 3.90.2 (payload, @payloadcms/ui, @payloadcms/plugin-seo 3.90.2, next 16.3.8, react 19.3.0, Node 24.21.0).

    Two data points that may help triage:

    1. No relationship is needed. Our array only has a select and a text field, plus a client-only RowLabel ('use client', reads useRowLabel()):

      {
        name: 'availability',
        type: 'array',
        admin: { components: { RowLabel: { path: '@/fields/icon-row-label#IconRowLabel', clientProps: { labelField: 'label' } } } },
        fields: [
          { name: 'icon', type: 'select', options: [/* ... */] },
          { name: 'label', type: 'text', required: true },
        ],
      }

      Clicking the MetaTitle "Auto-generate" button throws before the request is sent. The offending path in the body is initialState.layout.0.availability.rows.0.customComponents.RowLabel._payload.value._owner.props.payload.

    2. It only happens in development. In dev, React attaches _owner (debug info) to the RSC-rendered RowLabel element, and that owner's props include the payload instance. In a production build there's no _owner, so JSON.stringify succeeds. The rendered RowLabel trees are still sent in the body there, though (around 400 KB on one of our documents), so the root cause is the same.

    The fix looks like making sanitizeField in packages/ui/src/forms/Form/reduceToSerializableFields.ts also strip customComponents/validate from each rows[i] of array and blocks fields.

  5. added a commit that references this issue on Oct 28, 2026
    280c16c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSplugin: seostatus: needs-triagev3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions