From cc721609274d38d9a578575710edcb00d8064548 Mon Sep 17 00:00:00 2001 From: Oliver Stenbom Date: Wed, 11 Nov 2026 20:38:12 +0100 Subject: [PATCH] Log team invitations before responding, not after the email The invite activity was written in after(), behind the invitation email. When the email provider was slow (6-9s), the activity log didn't show the invite until well after the inviter saw "Invitation sent", which also made the team-invite-activity test flaky. Write the activity with the invitation and only defer the email. 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..38677bf 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); - }); + // The activity log is the team's record of what happened, so it is written + // with the invitation and is there as soon as the inviter looks for it. + await logActivity( + userWithTeam.teamId, + user.id, + ActivityType.INVITE_TEAM_MEMBER, + ); + + // The email provider has a slow tail, so send once the response has gone + // out and inviting still feels instant. + after(() => sendInvitationEmail(email, role)); return { success: "Invitation sent successfully", id: invitation[0].id }; },