From 26658d3afafc738ae8f2b5f4b949f183d9b239bb Mon Sep 17 00:00:00 2001 From: Sixian Li <43892874+atsixian@users.noreply.github.com> Date: Thu, 21 Mar 2024 06:34:51 +0800 Subject: [PATCH] fix: toast not displaying when `Toaster.duration` is set to Infinity (#373) --- src/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index b3ac8d1..765463b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -168,6 +168,11 @@ const Toast = (props: ToastProps) => { }; const startTimer = () => { + // setTimeout(, Infinity) behaves as if the delay is 0. + // As a result, the toast would be closed immediately, giving the appearance that it was never rendered. + // See: https://github.com/denysdovhan/wtfjs?tab=readme-ov-file#an-infinite-timeout + if (remainingTime === Infinity) return; + closeTimerStartTimeRef.current = new Date().getTime(); // Let the toast know it has started