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
23.08k stars 1.43k forks source link

Locale overwriting (critical bug) #7253

Closed ScapersClub closed 1 month ago

ScapersClub commented 1 month ago

Link to reproduction

No response

Payload Version

58-67

Node Version

latest

Next.js Version

recommended

Describe the Bug

When editing collections with localization, occasionally, for example, the en localization may be saved into the de localization and vice versa. As a result, the en and de localizations end up having identical content.

This may also be related to the use of upload fields (relatedTo: media), and when a file is uploaded through this field, we get an error in the Node.js console each time:

[12:40:49] ERROR: TypeError: Cannot read properties of undefined (reading 'length')
    at buildFormState (/Users/admin/Developer/project/.next/server/chunks/1ce68_@payloadcms_ui_dist_e0bc3a._.js:2403:28)
    at Object.buildFormState [as form-state] (/Users/admin/Developer/project/.next/server/chunks/a4ae4_@payloadcms_next_dist_04efc9._.js:1898:438)
    at /Users/admin/Developer/project/.next/server/chunks/a4ae4_@payloadcms_next_dist_04efc9._.js:3813:55
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:63352
    at async eP.execute (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54549)
    at async eP.handle (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:64693)
    at async doRender (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:1419:42)
    at async responseGenerator (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:1640:40)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:1665:28)
    at async DevServer.renderPageComponent (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:1978:24)
    at async DevServer.renderToResponseImpl (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:2016:32)
    at async DevServer.pipeImpl (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:908:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/next-server.js:273:17)
    at async DevServer.handleRequestImpl (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/base-server.js:804:17)
    at async /Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/dev/next-dev-server.js:339:20
    at async Span.traceAsyncFn (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/trace/trace.js:157:20)
    at async DevServer.handleRequest (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
    at async invokeRender (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/lib/router-server.js:175:21)
    at async handleRequest (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/lib/router-server.js:354:24)
    at async requestHandlerImpl (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/lib/router-server.js:378:13)
    at async Server.requestListener (/Users/admin/Developer/project/node_modules/.pnpm/next@15.0.0-rc.0_react-dom@19.0.0-rc-f994737d14-20240522_react@19.0.0-rc-f994737d14-20240522__y76pd2qdhh5v4o64f337tbjg7q/node_modules/next/dist/server/lib/start-server.js:142:13)

Reproduction Steps

It is not exactly known what causes this bug; it just happens from time to time.

Adapters and Plugins

db-mongodb storage-s3 richtext-slate

jentzheng commented 1 month ago

some additional info

  localization: {
    locales: ['en', 'fr']
    defaultLocale: 'en',
    fallback: true,
  }
...

Reproduction Steps

  1. Choose English as the default Payload Language and select "En" in the dropdown list
  2. Enter content in a collection for all locale.
  3. Go back to the collection list page then click the content link, it will redirect to the content edit form
  4. The locale param ?locale=en in the url of the edit form is not exist, the form value shows the secondary locale content rather the the default locale. If editor clicke save button, the "en" content will be overrided by the "fr" content
  5. Refresh the url, the secondary locale(such as fr) is being active
  6. Switch back to the default locale then the URL locale param ?locale=en is exist and the form shows the correct locale content

Payload Version

payload: 3.0.0-beta.67 next: 15.0.0-canary.74

JarrodMFlesch commented 1 month ago

@jentzheng I am not following, am I missing something in my screen recording?

https://github.com/user-attachments/assets/e25d6230-4283-49a1-8231-ee6e942eb8af

jentzheng commented 1 month ago

https://github.com/user-attachments/assets/1ad4b1f1-0e1d-47ea-a90d-913b6e4abd67

@JarrodMFlesch It seems the admin nav link is not getting the current locale and it always shows the non default locale content after first clicked.

"next": "15.0.0-canary.77",
"payload": "3.0.0-beta.68",
"@payloadcms/next": "3.0.0-beta.68"
"@payloadcms/db-postgres": "3.0.0-beta.68"
JarrodMFlesch commented 1 month ago

@jentzheng can you clear your node_modules, delete your pnpm-lock file, and then re-install deps? I am unable to replicate anything like this. If you want to link to a repository that I can boot up to replicate we can continue.

383bd03d commented 1 month ago

@jentzheng I am not following, am I missing something in my screen recording?

CleanShot.2024-07-22.at.10.30.40.mp4

I am experiencing a critical bug while using Payload CMS, particularly when editing complex pages with many fields, such as uploads and block types. The issue occurs frequently and is especially prevalent when multiple users are editing the same or different pages simultaneously. This bug results in significant data loss, as the work done is not saved and effectively "dead."

To reproduce the issue, create a complex landing page with numerous fields and blocks, similar to the payload page. When more than one user is editing a few pages, or even when a single user is working on a complex page, the bug occurs often, leading to lost work.

This issue is critical as it causes substantial disruption and loss of time when filling out content. Immediate attention and a fix would be greatly appreciated.

JarrodMFlesch commented 1 month ago

@jentzheng I am not following, am I missing something in my screen recording? CleanShot.2024-07-22.at.10.30.40.mp4

I am experiencing a critical bug while using Payload CMS, particularly when editing complex pages with many fields, such as uploads and block types. The issue occurs frequently and is especially prevalent when multiple users are editing the same or different pages simultaneously. This bug results in significant data loss, as the work done is not saved and effectively "dead."

To reproduce the issue, create a complex landing page with numerous fields and blocks, similar to the payload page. When more than one user is editing a few pages, or even when a single user is working on a complex page, the bug occurs often, leading to lost work.

This issue is critical as it causes substantial disruption and loss of time when filling out content. Immediate attention and a fix would be greatly appreciated.

Hey @383bd03d! Feel free to open an issue with a link to a reproduction and we can check it out šŸ‘

On another note, please do not attempt to hijack other users issue threads with unrelated comments.

jentzheng commented 1 month ago

@ScapersClub My db initialized since Payload beta.4x, try to delete the duplicated locale record in your db's table payload_preferences then it should solve the issue.

Screenshot 2024-07-30 at 01 04 28