From 5943a8ad643397c5494b4507b77ce60fd9394d6f Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Mon, 2 Mar 2026 17:05:07 +0400 Subject: [PATCH] fix: strip avatar and profile from children payload in managed event type updates (#28239) * fix: strip avatar and profile from children payload in managed event type updates When assigning users to managed event types with ~85+ users, the request body exceeds the 1MB server limit. The root cause is that the full ChildrenEventType objects (including avatar, profile, username, membership) are sent in the update payload, even though the server schema (childSchema) only needs owner.{id, name, email, eventTypeSlugs} and hidden. Avatar data can be particularly large when stored as base64 data URLs. With 85 users each having ~10KB+ avatars, the payload easily exceeds 1MB. This fix strips the children array down to only server-required fields before sending the mutation, while keeping the full data in form state for UI display purposes. Co-Authored-By: ali@cal.com * refactor: extract stripChildrenForPayload into shared utility instead of duplicating in test Addresses Cubic AI review feedback: the test file was duplicating the stripping logic instead of importing it from production code. - Extracted stripChildrenForPayload() into childrenEventType.ts - Updated useEventTypeForm.ts to import and use the shared function - Updated test file to import from production code instead of defining its own copy Co-Authored-By: bot_apk * fix: remove unused @ts-expect-error directive in useEventTypeForm Co-Authored-By: bot_apk --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: bot_apk --- .../eventtypes/lib/childrenEventType.ts | 18 +++ .../hooks/useEventTypeForm.test.ts | 151 ++++++++++++++++++ .../event-types/hooks/useEventTypeForm.ts | 28 ++-- 3 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 packages/platform/atoms/event-types/hooks/useEventTypeForm.test.ts diff --git a/packages/features/eventtypes/lib/childrenEventType.ts b/packages/features/eventtypes/lib/childrenEventType.ts index ed127cbdda..eb8dfcdda8 100644 --- a/packages/features/eventtypes/lib/childrenEventType.ts +++ b/packages/features/eventtypes/lib/childrenEventType.ts @@ -18,3 +18,21 @@ export type ChildrenEventType = { slug: string; hidden: boolean; }; + +/** + * Extracts only the fields needed by the server from a ChildrenEventType array. + * Display-only fields (avatar, profile, username, membership) are stripped to + * avoid bloating the request payload — with many assigned users (~85+), + * sending full objects can push the request body over the 1MB server limit. + */ +export function stripChildrenForPayload(children: ChildrenEventType[]) { + return children.map((child) => ({ + hidden: child.hidden, + owner: { + id: child.owner.id, + name: child.owner.name, + email: child.owner.email, + eventTypeSlugs: child.owner.eventTypeSlugs, + }, + })); +} diff --git a/packages/platform/atoms/event-types/hooks/useEventTypeForm.test.ts b/packages/platform/atoms/event-types/hooks/useEventTypeForm.test.ts new file mode 100644 index 0000000000..04d21ff9fa --- /dev/null +++ b/packages/platform/atoms/event-types/hooks/useEventTypeForm.test.ts @@ -0,0 +1,151 @@ +import { describe, it, expect } from "vitest"; + +import type { ChildrenEventType } from "@calcom/features/eventtypes/lib/childrenEventType"; +import { stripChildrenForPayload } from "@calcom/features/eventtypes/lib/childrenEventType"; +import { MembershipRole } from "@calcom/prisma/enums"; + +describe("useEventTypeForm - children payload stripping", () => { + it("should strip avatar, profile, username, and membership from children payload", () => { + const children: ChildrenEventType[] = [ + { + value: "1", + label: "Alice", + created: true, + slug: "test-event", + hidden: false, + owner: { + id: 1, + name: "Alice", + email: "alice@example.com", + username: "alice", + avatar: "data:image/png;base64," + "A".repeat(50000), // Large base64 avatar + membership: MembershipRole.MEMBER, + eventTypeSlugs: ["meeting", "consultation"], + profile: { + id: 1, + username: "alice", + upId: "usr_1", + organizationId: null, + organization: null, + }, + }, + }, + { + value: "2", + label: "Bob", + created: false, + slug: "test-event", + hidden: true, + owner: { + id: 2, + name: "Bob", + email: "bob@example.com", + username: "bob", + avatar: "https://example.com/avatars/bob.png", + membership: MembershipRole.OWNER, + eventTypeSlugs: [], + profile: { + id: 2, + username: "bob", + upId: "usr_2", + organizationId: 10, + organization: { + id: 10, + slug: "org", + name: "Org", + calVideoLogo: null, + bannerUrl: "", + isPlatform: false, + }, + }, + }, + }, + ]; + + const stripped = stripChildrenForPayload(children); + + // Should only contain server-needed fields + expect(stripped).toEqual([ + { + hidden: false, + owner: { + id: 1, + name: "Alice", + email: "alice@example.com", + eventTypeSlugs: ["meeting", "consultation"], + }, + }, + { + hidden: true, + owner: { + id: 2, + name: "Bob", + email: "bob@example.com", + eventTypeSlugs: [], + }, + }, + ]); + + // Verify avatar is not present + for (const child of stripped) { + expect(child.owner).not.toHaveProperty("avatar"); + expect(child.owner).not.toHaveProperty("profile"); + expect(child.owner).not.toHaveProperty("username"); + expect(child.owner).not.toHaveProperty("membership"); + } + }); + + it("should significantly reduce payload size for large teams", () => { + // Simulate 85 users with base64 avatars (~10KB each) + const largeBase64Avatar = "data:image/png;base64," + "A".repeat(10000); + + const children: ChildrenEventType[] = Array.from({ length: 85 }, (_, i) => ({ + value: String(i + 1), + label: `User ${i + 1}`, + created: true, + slug: "managed-event", + hidden: false, + owner: { + id: i + 1, + name: `User ${i + 1}`, + email: `user${i + 1}@example.com`, + username: `user${i + 1}`, + avatar: largeBase64Avatar, + membership: MembershipRole.MEMBER, + eventTypeSlugs: ["event-a", "event-b"], + profile: { + id: i + 1, + username: `user${i + 1}`, + upId: `usr_${i + 1}`, + organizationId: 1, + organization: { + id: 1, + slug: "org", + name: "Large Org", + calVideoLogo: null, + bannerUrl: "", + isPlatform: false, + }, + }, + }, + })); + + const fullPayloadSize = JSON.stringify(children).length; + const strippedPayloadSize = JSON.stringify(stripChildrenForPayload(children)).length; + + // The stripped payload should be dramatically smaller + expect(strippedPayloadSize).toBeLessThan(fullPayloadSize * 0.1); + + // Full payload with 85 users and 10KB avatars should be around 850KB+ + expect(fullPayloadSize).toBeGreaterThan(800000); + + // Stripped payload should be well under 1MB + expect(strippedPayloadSize).toBeLessThan(100000); + }); + + it("should handle undefined children gracefully", () => { + const children: ChildrenEventType[] = []; + const stripped = stripChildrenForPayload(children); + expect(stripped).toEqual([]); + }); +}); diff --git a/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts b/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts index 625279de04..8e4f5c51eb 100644 --- a/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts +++ b/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts @@ -1,23 +1,23 @@ -import { zodResolver } from "@hookform/resolvers/zod"; -import { useMemo, useState, useEffect } from "react"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; - import checkForMultiplePaymentApps from "@calcom/app-store/_utils/payments/checkForMultiplePaymentApps"; import { locationsResolver } from "@calcom/app-store/locations"; -import { DEFAULT_PROMPT_VALUE, DEFAULT_BEGIN_MESSAGE } from "@calcom/features/calAIPhone/promptTemplates"; +import { DEFAULT_BEGIN_MESSAGE, DEFAULT_PROMPT_VALUE } from "@calcom/features/calAIPhone/promptTemplates"; import type { TemplateType } from "@calcom/features/calAIPhone/zod-utils"; import { validateCustomEventName } from "@calcom/features/eventtypes/lib/eventNaming"; -import { sortHosts } from "@calcom/lib/bookings/hostGroupUtils"; +import { stripChildrenForPayload } from "@calcom/features/eventtypes/lib/childrenEventType"; import type { - FormValues, EventTypeSetupProps, EventTypeUpdateInput, + FormValues, } from "@calcom/features/eventtypes/lib/types"; +import { sortHosts } from "@calcom/lib/bookings/hostGroupUtils"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder"; import { validateBookerLayouts } from "@calcom/lib/validateBookerLayouts"; import { eventTypeBookingFields as eventTypeBookingFieldsSchema } from "@calcom/prisma/zod-utils"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useEffect, useMemo, useState } from "react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; type Fields = z.infer; @@ -287,13 +287,11 @@ export const useEventTypeForm = ({ const updatedFields: Partial = {}; Object.keys(dirtyFields).forEach((key) => { const typedKey = key as keyof typeof dirtyFields; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore updatedFields[typedKey] = undefined; const isDirty = isFieldDirty(typedKey); if (isDirty) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore + // @ts-expect-error updatedFields[typedKey] = values[typedKey]; } }); @@ -381,6 +379,12 @@ export const useEventTypeForm = ({ // eslint-disable-next-line @typescript-eslint/no-unused-vars const { availability, users, scheduleName, disabledCancelling, disabledRescheduling, ...rest } = input; + // Strip children down to only the fields the server schema expects. + // The full children objects contain avatar, profile, and other display-only + // data that bloats the request payload. With many assigned users (~85+), + // this can push the request body over the 1MB server limit. + const strippedChildren = children ? stripChildrenForPayload(children) : undefined; + const payload = { ...rest, length, @@ -402,7 +406,7 @@ export const useEventTypeForm = ({ seatsShowAvailabilityCount, metadata, customInputs, - children, + children: strippedChildren, assignAllTeamMembers, multiplePrivateLinks: values.multiplePrivateLinks, disableCancelling: disabledCancelling,