payload
payload copied to clipboard
A lot of aborted / error building form state / cannot read length of undefined in the server error logs
Link to reproduction
No response
Payload Version
3.0.0-beta.78
Node Version
20 LTS
Next.js Version
15.0.0-canary.104
Describe the Bug
We have a lot of entries in the logs from normal author usage:
[13:54:21] [31mERROR[39m: [36maborted[39m
err: {
"type": "Error",
"message": "aborted",
"stack":
Error: aborted
at abortIncoming (node:_http_server:797:17)
at socketOnClose (node:_http_server:791:3)
at Socket.emit (node:events:531:35)
at TCP.<anonymous> (node:net:339:12)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
"code": "ECONNRESET"
}
[13:54:21] [31mERROR[39m: [36mThere was an error building form state[39m
err: {
"type": "TypeError",
"message": "Cannot read properties of undefined (reading 'length')",
"stack":
TypeError: Cannot read properties of undefined (reading 'length')
at f (webpack://babu-cms/node_modules/@payloadcms/ui/dist/utilities/buildFormState.js:56:1)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at Object.tA (webpack://babu-cms/node_modules/@payloadcms/next/dist/routes/rest/buildFormState.js:11:1)
at <anonymous> (webpack://babu-cms/node_modules/@payloadcms/next/dist/routes/rest/index.js:505:1)
at <anonymous> (webpack://next/dist/src/server/route-modules/app-route/module.ts:381:33)
at eP.execute (webpack://next/dist/src/server/route-modules/app-route/module.ts:283:31)
at eP.handle (webpack://next/dist/src/server/route-modules/app-route/module.ts:483:24)
at doRender (/app/node_modules/next/src/server/base-server.ts:2467:30)
at responseGenerator (/app/node_modules/next/src/server/base-server.ts:2858:22)
at NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/src/server/base-server.ts:2870:24)
}
[13:54:21] [31mERROR[39m: [36mTypeError: Cannot read properties of undefined (reading 'length')
at f (webpack://babu-cms/node_modules/@payloadcms/ui/dist/utilities/buildFormState.js:56:1)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at Object.tA (webpack://babu-cms/node_modules/@payloadcms/next/dist/routes/rest/buildFormState.js:11:1)
at <anonymous> (webpack://babu-cms/node_modules/@payloadcms/next/dist/routes/rest/index.js:505:1)
at <anonymous> (webpack://next/dist/src/server/route-modules/app-route/module.ts:381:33)
at eP.execute (webpack://next/dist/src/server/route-modules/app-route/module.ts:283:31)
at eP.handle (webpack://next/dist/src/server/route-modules/app-route/module.ts:483:24)
at doRender (/app/node_modules/next/src/server/base-server.ts:2467:30)
at responseGenerator (/app/node_modules/next/src/server/base-server.ts:2858:22)
at NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/src/server/base-server.ts:2870:24)[39m
I don't think there is something wrong with our setup but this is more of a general error that arises all the time in the back without the authors noticing.
Any clue what this could be?
Reproduction Steps
Unclear. We have this from our production logs.
Adapters and Plugins
db-postgres
@jacobsfletch this is due to us aborting the fetch request to buildFormState. We need to figure out another pattern there. It seems like Next.js is not bailing out of the request on the backend when the frontend signals to abort.
If you make fetches in a useEffect, or a useEffect calls a function that makes a fetch, React suggests to use the abort controller. Maybe we should do some testing and digging to see if there is any more info about this topic.
@jmikrut just opened a PR which just not logs the error , it's not resolving the next.js issue https://github.com/payloadcms/payload/pull/8223 But it can help us a lot to get cleaner logs
I'm also getting this error on beta.122, I haven't noticed any problems caused from this error, however, the client is reporting autosaves reverting to the last published document that I'm yet to get to the bottom of.
Since v3.0.0-beta.128 we completely changed the way that form-state is retrieved, and we've also relaxed some of the logs. Can anyone confirm if this is still an issue in the latest version? Currently v3.1.0.
Closing for now. If anyone is able to reproduce, we can re-open this issue.
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.