This commit is contained in:
rgrgogu
2026-07-25 10:22:52 +08:00
parent a546a57c17
commit 48dd501d17
+8 -1
View File
@@ -75,7 +75,14 @@ export default function CourseCheckout() {
if (!wasCancelled) return; if (!wasCancelled) return;
const orderId = searchParams.get("token"); const orderId = searchParams.get("token");
if (orderId) cancelCourseOrder(orderId); if (orderId) cancelCourseOrder(orderId);
toast("Payment was cancelled."); // Deferred to a new macrotask: this page renders as an <Outlet /> child,
// which sits before <Toaster /> in ClientLayout's JSX — so a toast fired
// synchronously in this mount-time effect races the Toaster's own mount
// effect (which subscribes to sonner's store) and is silently dropped,
// since sonner only notifies subscribers already listening at publish
// time (no replay for late subscribers). setTimeout(0) pushes the call
// past the current effect-flush, after Toaster has subscribed.
setTimeout(() => toast("Payment was cancelled."), 0);
navigate(`/course/${courseId}/checkout`, { replace: true }); navigate(`/course/${courseId}/checkout`, { replace: true });
}, [wasCancelled]); // eslint-disable-line react-hooks/exhaustive-deps }, [wasCancelled]); // eslint-disable-line react-hooks/exhaustive-deps