Skip to content

Bug: autosave & publish intermittently 500 on Vercel — TypeError: Cannot read properties of undefined (reading '_status' | 'title') — multipart body dropped when Content-Length is absent (Transfer-Encoding: chunked) #16351

Closed

Description

@DarioSiroki

Describe the Bug

Affects every Payload deployment on Vercel with the admin UI. Symptom is user-visible: save and publish buttons randomly 500; retrying ~30s later usually succeeds, which makes it hard to correlate. One-line fix available, already verified against Payload 3.83.0.

Summary

packages/payload/src/utilities/addDataAndFileToRequest.ts requires a truthy bodyByteSize (derived from Content-Length) before it parses a multipart body. When a multipart PATCH arrives with Transfer-Encoding: chunked and no Content-Length — which Vercel's edge produces intermittently for admin requests — the multipart branch is skipped, req.data stays undefined, and every downstream operation that reads req.data crashes.

Autosave path (via updateByID → updateDocument):

TypeError: Cannot read properties of undefined (reading '_status')
    at packages/payload/src/collections/operations/utilities/update.ts:67
    // const isSavingDraft = ... && data._status !== 'published' ...

Publish path (same undefined data propagates into field hooks):

TypeError: Cannot read properties of undefined (reading 'title')
    at packages/payload/src/fields/hooks/beforeValidate/promise.ts:~179
    // siblingData[field.name]   ← siblingData = incomingData = undefined

Same root cause. The property name in the second error is whatever field traverseFields touches first.

Offending code

packages/payload/src/utilities/addDataAndFileToRequest.ts (around line 18):

const bodyByteSize = parseInt(req.headers.get('Content-Length') || '0', 10)
// ...
} else if (bodyByteSize && contentType?.includes('multipart/')) {
  // parse multipart, set req.data…
}

If Content-Length is missing, bodyByteSize === 0 and the multipart block never runs.

Why this is inconsistent with the rest of the package

packages/payload/src/uploads/fetchAPI-multipart/isEligibleRequest.ts already gets this right:

const hasBody = (req: Request) =>
  Boolean(
    req.headers.get('transfer-encoding') ||
    (req.headers.get('content-length') && req.headers.get('content-length') !== '0'),
  )

The multipart parser itself handles chunked bodies correctly — only the outer guard in addDataAndFileToRequest is wrong.

Suggested fix

One-line change to mirror the guard above:

-  } else if (bodyByteSize && contentType?.includes('multipart/')) {
+  } else if ((bodyByteSize || headers.get('transfer-encoding')) && contentType?.includes('multipart/')) {

Happy to open a PR if this approach is acceptable.

Captured prod request (for context)

One failing request logged via a route-handler wrapper on our deployment:

{
  "method": "PATCH",
  "url": "https://<redacted>/api/properties/6?autosave=true&draft=true&locale=de",
  "contentType": "multipart/form-data; boundary=----WebKitFormBoundary…",
  "contentLength": null,
  "transferEncoding": "chunked",
  "bodyIsNull": false,
  "bodyUsed": false,
  "vercelId": "fra1::…"
}

Result: 500 within ~70ms, TypeError: Cannot read properties of undefined (reading '_status').

Link to the code that reproduces this issue

https://github.com/DarioSiroki/payload-repro-multipart-chunked

Reproduction Steps

No Vercel needed — Node's fetch() auto-sends Transfer-Encoding: chunked without a Content-Length header whenever the body is a ReadableStream, which is the exact wire condition Vercel's edge sometimes produces (it really is random, verified by calling the same endpoint many times and logging the request headers).

git clone https://github.com/DarioSiroki/payload-repro-multipart-chunked
cd payload-repro-multipart-chunked
pnpm install
pnpm dev     # shell 1 — leaves admin running at http://localhost:3000
pnpm repro   # shell 2 — sends one chunked multipart PATCH and prints the result

Expected results:

Payload source pnpm repro exit Server log
Unmodified 3.83.0 status=500 / exit 1 TypeError: Cannot read properties of undefined (reading '_status')
With the one-line fix applied status=200 / exit 0 clean

Verbatim A/B locally verified:

  • Pre-fix: status=500 + {"errors":[{"message":"Something went wrong."}]}
  • Post-fix: status=200 + PASS — server parsed the chunked multipart body.

Which area(s) are affected?

area: core

Environment Info

Binaries:
  Node: 24.13.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.0.0
Relevant Packages:
  payload: 3.83.0
  next: 16.2.4
  @payloadcms/db-sqlite: 3.83.0
  @payloadcms/drizzle: 3.83.0
  @payloadcms/graphql: 3.83.0
  @payloadcms/next/utilities: 3.83.0
  @payloadcms/richtext-lexical: 3.83.0
  @payloadcms/translations: 3.83.0
  @payloadcms/ui/shared: 3.83.0
  react: 19.2.4
  react-dom: 19.2.4
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0


Also reproduced on production deployment:
- Payload 3.83.0, `@payloadcms/next` 3.83.0, Next.js 16.2.4
- PostgreSQL via `@payloadcms/db-postgres` 3.83.0
- Vercel serverless runtime, Frankfurt (`fra1`) region

Offending line also present in 3.80.0 and earlier — unsafe guard predates 3.83.

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Apr 22, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Apr 22, 2026
  3. DarioSiroki commented on Apr 22, 2026

    @DarioSiroki
    Author

    Update - I was quick on the trigger.

    This appears to already be fixed on main by #16301. The PR title frames it as an Azure streaming-uploads fix, but the guard change in addDataAndFileToRequest.ts (adding the hasBodyStream fallback) covers this case too

    Not in any released tag yet, so every published version still hits this. Flagging because the user-visible symptom here - admin save/publish randomly 500ing on Vercel - is a broader blast radius than the uploads-focused framing of #16301, and affects every Payload-on-Vercel admin deployment.

    I will take care of closing this once the fix ships in a release.

  4. DarioSiroki commented on Apr 23, 2026

    @DarioSiroki
    Author

    Fixed via 3.84.0

  5. removed
    status: needs-triage
    on Apr 23, 2026
  6. github-actions commented on Apr 30, 2026

    @github-actions
    Contributor

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

  7. locked as resolved and limited conversation to collaborators on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions