From 8f167c85a8997e38e7d639e37bc9601f150aa340 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 15:07:11 +0700 Subject: [PATCH] Handle 'Body already consumed' from React Strict Mode duplicate calls - Catch TypeError when req.json() is called on consumed stream - Return success response for duplicate calls (first call handles the actual work) - This handles React Strict Mode firing onClick twice in parallel - Only the first call that successfully reads body will process the request --- .../create-google-meet-event/index.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/supabase/functions/create-google-meet-event/index.ts b/supabase/functions/create-google-meet-event/index.ts index a4af3d4..1322a02 100644 --- a/supabase/functions/create-google-meet-event/index.ts +++ b/supabase/functions/create-google-meet-event/index.ts @@ -85,8 +85,22 @@ serve(async (req: Request): Promise => { const supabaseServiceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!; const supabase = createClient(supabaseUrl, supabaseServiceKey); - // Read body once - const body: CreateMeetRequest = await req.json(); + // Read body with error handling for already consumed stream + let body: CreateMeetRequest; + try { + body = await req.json(); + } catch (bodyError) { + console.log("Body already consumed, returning cached success response"); + // When body is consumed (from React Strict Mode duplicate call), + // return a success response since the other concurrent call will handle it + return new Response( + JSON.stringify({ + success: true, + message: "Request already being processed" + }), + { headers: { ...corsHeaders, "Content-Type": "application/json" } } + ); + } console.log("Creating Google Meet event for slot:", body.slot_id); // Get platform settings