From d7c10d3ee9315f11dc2cb1a9456c125c297f111d Mon Sep 17 00:00:00 2001 From: Oliver Stenbom Date: Thu, 12 Nov 2026 14:44:38 +0100 Subject: [PATCH] Log team invites before responding, not after the email The invite was only written to the activity log after the invitation email had been sent, inside after(). A slow email send (up to 9s) kept the invite out of the activity log well after the form said it was sent, which made team-invite-activity.spec.ts fail about a third of the time. Log the invite before responding, as every other action does, and keep only the email in after(). Co-Authored-By: Claude Opus 5.5 --- app/(login)/actions.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/(login)/actions.ts b/app/(login)/actions.ts index cd45efc..e81243f 100644 --- a/app/(login)/actions.ts +++ b/app/(login)/actions.ts @@ -339,13 +339,17 @@ export const inviteTeamMember = validatedActionWithUser( }) .returning(); - // Email the invitee and log the invite once the response has been sent, - // so inviting feels instant. - const teamId = userWithTeam.teamId; - after(async () => { - await sendInvitationEmail(email, role); - await logActivity(teamId, user.id, ActivityType.INVITE_TEAM_MEMBER); - }); + // Log the invite before responding, so the activity log is up to date as + // soon as the invite form says it was sent. + await logActivity( + userWithTeam.teamId, + user.id, + ActivityType.INVITE_TEAM_MEMBER, + ); + + // Email the invitee once the response has been sent, so a slow email + // provider doesn't slow down inviting. + after(() => sendInvitationEmail(email, role)); return { success: "Invitation sent successfully", id: invitation[0].id }; },