The booking was saved, but the customer saw an error: email after commit in Next.js
This bug made it into the released versions of my Next.js 15 templates (two booking sites, a barbershop and a dental clinic, and two small online stores). All the tests were green. The booking flow had a row lock, an idempotency key and a race test. And it could still book the same customer twice. Here's the flow it broke: The customer submits the form. The appointment is committed to Postgres.…
In the release of Next.js 15 templates, a bug caused customers to receive duplicate bookings. The email notification after form submission sometimes failed, despite the appointment being saved to the database. This resulted in customers seeing an error and the system marking the booking as successful. To address this, the author implemented several fixes.
First, the email sending function sendMail was modified to return false instead of throwing an exception upon failure, allowing the system to log the error without causing a booking failure. Second, the book() function was updated to include a separate try/catch block for any code running after the appointment is saved, ensuring that any post-commit errors do not alter the booking status.
This change was applied similarly to the Stripe webhook, where the email sending step was isolated in a try/catch block to prevent the webhook from returning an error. Finally, the UI displayed the correct email status, informing users whether their confirmation email was sent or not, even if the SMTP server was down. This set of changes aimed to prevent the occurrence of duplicate bookings caused by email failure, improving the overall user experience.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to