From 0e8073f8d52395868903a64a86e020627fd8d520 Mon Sep 17 00:00:00 2001 From: Ido Shamun <1993245+idoshamun@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:48:10 +0000 Subject: [PATCH] fix: prevent empty image object from being sent in freeform post creation 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 --- packages/shared/src/graphql/posts.ts | 7 ++++++- packages/webapp/pages/squads/create.tsx | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/graphql/posts.ts b/packages/shared/src/graphql/posts.ts index 937a04e1952..5871afd723e 100644 --- a/packages/shared/src/graphql/posts.ts +++ b/packages/shared/src/graphql/posts.ts @@ -960,12 +960,17 @@ export type CreatePostInMultipleSourcesResponse = Array<{ export const createPostInMultipleSources = async ( variables: CreatePostInMultipleSourcesArgs, ) => { + const { image, ...rest } = variables; + const sanitized = { + ...rest, + ...(image instanceof File && image.size > 0 ? { image } : {}), + }; const res = await gqlClient.request< { createPostInMultipleSources: CreatePostInMultipleSourcesResponse; }, CreatePostInMultipleSourcesArgs - >(CREATE_POST_IN_MULTIPLE_SOURCES, variables); + >(CREATE_POST_IN_MULTIPLE_SOURCES, sanitized); return res.createPostInMultipleSources; }; diff --git a/packages/webapp/pages/squads/create.tsx b/packages/webapp/pages/squads/create.tsx index 558bf9d91c0..cbf8d94701f 100644 --- a/packages/webapp/pages/squads/create.tsx +++ b/packages/webapp/pages/squads/create.tsx @@ -182,10 +182,11 @@ function CreatePost(): ReactElement { return; } - const { options, ...args } = params; + const { options, image, ...args } = params; await onCreate({ ...args, + ...(image instanceof File && image.size > 0 && { image }), ...(options?.length && { options: options.map((text, order) => ({ text,