tinacms / tinacms

A fully open-source headless CMS that supports Markdown and Visual Editing
https://tina.io
Apache License 2.0
11.19k stars 564 forks source link

Regression: nested MDX objects throw parse error #4484

Closed jeffsee55 closed 1 week ago

jeffsee55 commented 1 month ago

Nested object structures in MDX template fields throw an error, config:

import { RichTextField } from '@tinacms/schema-tools'

export const field: RichTextField = {
  name: 'body',
  type: 'rich-text',
  parser: { type: 'mdx' },
  templates: [
    {
      name: 'Table',
      fields: [
        {
          name: 'rows',
          type: 'object',
          list: true,
          fields: [
            {
              name: 'columns',
              type: 'object',
              list: true,
              fields: [
                {
                  name: 'content',
                  type: 'rich-text',
                },
              ],
            },
          ],
        },
      ],
    },
  ],
}

And value:

<Table rows={[
    {
      columns: [
        {
          content: {
            type: "root",
            children: []
          }
        }
      ]
    }
  ]} />

Cause this error:

Unable to parse field value for field \"rows\" (type: object). Expected type to be Literal but received ObjectExpression
jmarks-joshua commented 1 month ago

For me this works as I'm embedding and entering the data for the template, but then gives this error only on refresh of the browser. Not sure if that is helpful, but thought I'd add just in case.

JackDevAU commented 1 week ago

I'm excited to announce that the issue regarding nested MDX objects has been resolved 🎉

How to Update and Test:

Update your TinaCMS package to version 1.6.3:

npm i tinacms

Refer to this example (if you want to try it out): https://github.com/tinacms/tinacms/blob/598bb59701e05643d27d472b415d3b81c3ec27fc/packages/%40tinacms/mdx/src/next/tests/mdx-basic-nested-objects-2/field.ts