Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drafts autosave: Error building form state - Cannot read properties of null (reading '_id') #10572

Open
Collexi-Dev opened this issue Jan 14, 2025 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@Collexi-Dev
Copy link

Describe the Bug

When editing documents, i.e. adding / removing blocks or items, if autosave is enabled occasionally the following error occurs:

[16:49:55] ERROR: There was an error building form state
    err: {
      "type": "TypeError",
      "message": "Cannot read properties of null (reading '_id')",
      "stack":
          TypeError: Cannot read properties of null (reading '_id')
              at Object.updateOne (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected]_@aws-sdk+client-sso-oidc@_7gkyaxq7c2tb6culk4azy6wsei/node_modules/@payloadcms/db-mongodb/dist/updateOne.js:55:24)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async handleFormStateLocking (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_r_h5irrt4qzojdy236los5gpcbcq/node_modules/@payloadcms/ui/dist/utilities/handleFormStateLocking.js:67:11)
              at async buildFormState (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_r_h5irrt4qzojdy236los5gpcbcq/node_modules/@payloadcms/ui/dist/utilities/buildFormState.js:168:25)
              at async buildFormStateHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_r_h5irrt4qzojdy236los5gpcbcq/node_modules/@payloadcms/ui/dist/utilities/buildFormState.js:56:17)
              at async /PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:157:2088
              at async handleAction (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:156:21940)
              at async renderToHTMLOrFlightImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:161:22397)
              at async doRender (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1574:34)
              at async responseGenerator (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1822:28)
              at async DevServer.renderToResponseWithComponentsImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1832:28)
              at async DevServer.renderPageComponent (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:2259:24)
              at async DevServer.renderToResponseImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:2297:32)
              at async DevServer.pipeImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:959:25)
              at async NextNodeServer.handleCatchallRenderRequest (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js:281:17)
              at async DevServer.handleRequestImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:853:17)
              at async /PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:371:20
              at async Span.traceAsyncFn (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/trace/trace.js:153:20)
              at async DevServer.handleRequest (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:368:24)
              at async invokeRender (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:230:21)
              at async handleRequest (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:408:24)
              at async requestHandlerImpl (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:432:13)
              at async Server.requestListener (/PayloadCMS-Testing/20250114-latest-template/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:146:13)
    }

The error makes it so that when you're inserting blocks or items they sometimes stay in the loading state because of the error and you need to remove and re-add it which is rather annoying to explain to a client.

When autosave is disabled the issue goes away. Not sure if it's MongoDB specific or not.

Link to the code that reproduces this issue

https://github.com/Collexi-Dev/test-payload-3-stable

Reproduction Steps

  1. Clone latest website template
  2. Set up with MongoDB Atlas
  3. Repeatedly add/remove a block or item from an array in the admin panel until error occurs

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 20.13.1
  npm: 10.5.2
  Yarn: 1.22.22
  pnpm: 9.12.2
Relevant Packages:
  payload: 3.17.1
  next: 15.1.4
  @payloadcms/db-mongodb: 3.17.1
  @payloadcms/email-nodemailer: 3.17.1
  @payloadcms/graphql: 3.17.1
  @payloadcms/live-preview: 3.17.1
  @payloadcms/live-preview-react: 3.17.1
  @payloadcms/next/utilities: 3.17.1
  @payloadcms/payload-cloud: 3.17.1
  @payloadcms/plugin-form-builder: 3.17.1
  @payloadcms/plugin-nested-docs: 3.17.1
  @payloadcms/plugin-redirects: 3.17.1
  @payloadcms/plugin-search: 3.17.1
  @payloadcms/plugin-seo: 3.17.1
  @payloadcms/richtext-lexical: 3.17.1
  @payloadcms/translations: 3.17.1
  @payloadcms/ui/shared: 3.17.1
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 19:02:12 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14
@Collexi-Dev Collexi-Dev added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant