In Remix / React Router v7, form submit action functions are hanging for 2+ seconds while waiting for email API responses before redirecting the user. How can we make form submissions instant?
Remix and React Router v7 action functions timing out on slow SMTP connections — architectural fixes
The Bottleneck with Synchronous Actions
In Remix / React Router v7, a server action blocks UI submission state until it returns a Response or redirect(). Waiting for external email API network roundtrips directly inside the request loop adds noticeable UI latency.
Fix 1: Optimistic Non-Awaited Dispatch (Fast Path)
If immediate delivery confirmation isn’t required in UI, dispatch the promise without blocking the redirect() return:
// app/routes/signup.tsx
import { redirect, type ActionFunctionArgs } from '@remix-run/node';
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const email = formData.get('email') as string;
const user = await db.user.create({ data: { email } });
// Trigger background promise without blocking response return
fetch('https://api.autosend.com/v1/mails/send', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AUTOSEND_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: { email: 'welcome@yourdomain.com', name: 'App' },
to: { email },
subject: 'Welcome to our platform!',
html: '<p>Click below to verify...</p>'
})
}).catch(err => console.error('Background email failed:', err));
return redirect('/dashboard');
}
Fix 2: Queue Workers (Production Path)
For production systems, push the job to an async queue like Redis/BullMQ or Cloudflare Queues so background workers handle retries, throttling, and logging independently of the frontend request.