payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.5k stars 1.55k forks source link

Localized blocks inside localized blocks not working properly across multiple locales #7805

Closed tiago-meireles closed 1 month ago

tiago-meireles commented 1 month ago

Link to reproduction

No response

Payload Version

beta.87

Node Version

20 LTS

Next.js Version

15.0.0-canary.104

Describe the Bug

Blocks inside localized blocks are creating multiple content occurrences. Localized Blocks inside localized blocks cannot be migrated.

Here's the issue in detail

https://github.com/user-attachments/assets/c561e35d-7261-4b75-ae34-529931d5068c

To test this, created 2 blocks (BlockInsideBlock and MediaBlock)

MediaBlock

export const MediaBlock: Block = {
  slug: 'media',
  interfaceName: 'MediaBlock',
  labels: {
    singular: 'Media Block',
    plural: 'Media Blocks',
  },
  fields: [
    {
      name: 'media',
      label: 'Media',
      type: 'upload',
      relationTo: 'media',
      required: true,
    },
  ],
}

BlockInsideBlock

export const BlockInsideBlock: Block = {
  slug: 'blockInsideBlock',
  interfaceName: 'BlockInsideBlock',
  fields: [
    {
      name: 'content',
      label: 'Block',
      type: 'blocks',
      // localized: true,
      labels: {
        singular: 'Block',
        plural: 'Blocks',
      },
      blocks: [MediaBlock],
    },
  ],
}

I then added a localized blocks field with the BlockInsideBlock to the existing fields of the Pages collection.

    {
      name: 'content', 
      label: 'Content',
      type: 'blocks',
      localized: true,
      blocks: [BlockInsideBlock],
    },

Since the Media content was the same between the EN and FR locales, I tried to add localization to the content field in the BlockInsideBlock (currently commented), but I always get the error ERROR (payload): Error: cannot connect to Postgres. Details: Cannot read properties of undefined (reading 'Symbol(drizzle:Name)') when creating the migrations.

Is there any current restrictions in the use of blocks inside blocks that could be causing the migrate:create command to fail with this error message? Or for the duplication of content for blocks inside blocks?

Reproduction Steps

  1. Use the beta demo project
  2. Update to version 87
  3. Create the MediaBlock and the BlockInsideBlock
  4. Add the new Page field (as described above) to the existing Page fields
  5. Run the necessary migrations
  6. Follow the same steps as the ones in the video to check that the content in the block inside the block keeps multiplying every time the page autosaves or if another locale is configured.
  7. Remove the comment from the BlockInsideBlock and make that field localized
  8. Run the migrate:create command and see that the error ERROR (payload): Error: cannot connect to Postgres. Details: Cannot read properties of undefined (reading 'Symbol(drizzle:Name)') is presented

Adapters and Plugins

db-postgres

jmikrut commented 1 month ago

The duplication errors are now resolved! For anyone else finding this in the future, note that the "localized within localized" fields have not been fixed as a result of the above PR, because we are going to prevent that type of configuration in the future as it is not necessary / valid to have a localized field within a localized field.

github-actions[bot] commented 1 month ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.