Skip to content

fix: prevent empty image object from being sent in freeform post creation#5874

Merged
idoshamun merged 1 commit intomainfrom
fix/empty-image-object-freeform-post
Apr 16, 2026
Merged

fix: prevent empty image object from being sent in freeform post creation#5874
idoshamun merged 1 commit intomainfrom
fix/empty-image-object-freeform-post

Conversation

@idoshamun
Copy link
Copy Markdown
Member

@idoshamun idoshamun commented Apr 16, 2026

Problem

When creating a freeform post without a thumbnail image, the image field is sent as an empty object {} in the GraphQL variables. graphql-request v3 serializes File objects as {} in JSON since File has no enumerable own properties. The API receives this {}, enters the Cloudinary upload path (because {} is truthy), tries to call createReadStream() on it, and crashes with "Unexpected error".

Reported in dailydotdev/daily#2095.

Fix

Strip the image field from the mutation variables unless it is a valid File instance with non-zero size:

  1. packages/webapp/pages/squads/create.tsx — destructure image out of params and only spread it back when valid
  2. packages/shared/src/graphql/posts.ts — defensive sanitization in createPostInMultipleSources() before sending the request

Testing

  • Create a freeform post without selecting a thumbnail → should succeed (no Unexpected error)
  • Create a freeform post with a thumbnail image → should still upload correctly

Preview domain

https://fix-empty-image-object-freeform.preview.app.daily.dev

…tion

When creating a freeform post without a thumbnail image, the image field
could be sent as an empty/invalid object ({}) to the API. This happens
because the form's file input produces a value that isn't a valid File
but is still truthy, so graphql-request serializes it as {} in the JSON
payload. The API then tries to process it as a file upload and crashes
with 'Unexpected error'.

Fix: strip the image field from the GraphQL variables unless it is a
valid File instance with non-zero size. Applied both at the call site
(create.tsx) and defensively in the shared createPostInMultipleSources
function.

Closes dailydotdev/daily#2095
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
daily-webapp Ready Ready Preview Apr 16, 2026 10:52am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
storybook Ignored Ignored Apr 16, 2026 10:52am

Request Review

@idoshamun idoshamun merged commit fa38cc9 into main Apr 16, 2026
10 of 12 checks passed
@idoshamun idoshamun deleted the fix/empty-image-object-freeform-post branch April 16, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant