From 1cf5fad881b1da8f96923b7ad81d22d0aa3574b9 Mon Sep 17 00:00:00 2001 From: ocavue Date: Tue, 21 Nov 2023 20:13:44 +0800 Subject: [PATCH] fix(toast): replace MAX_VALUE with MAX_SAFE_INTEGER (#1982) This PR replaces the maximum id from `Number.MAX_VALUE` to `Number.MAX_SAFE_INTEGER` in `use-toast.ts`. Considering how JS stores numbers, it's unsafe to plus one if the number is larger than `Number.MAX_SAFE_INTEGER`. Here is an example: ```js > let num > num = Number.MAX_VALUE - 1 > num + 1 === num true > num = Number.MAX_SAFE_INTEGER - 1 > num + 1 === num false ``` --- apps/www/registry/default/ui/use-toast.ts | 2 +- apps/www/registry/new-york/ui/use-toast.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/www/registry/default/ui/use-toast.ts b/apps/www/registry/default/ui/use-toast.ts index b38cacbd749..3a9b24b4a73 100644 --- a/apps/www/registry/default/ui/use-toast.ts +++ b/apps/www/registry/default/ui/use-toast.ts @@ -26,7 +26,7 @@ const actionTypes = { let count = 0 function genId() { - count = (count + 1) % Number.MAX_VALUE + count = (count + 1) % Number.MAX_SAFE_INTEGER return count.toString() } diff --git a/apps/www/registry/new-york/ui/use-toast.ts b/apps/www/registry/new-york/ui/use-toast.ts index b38cacbd749..3a9b24b4a73 100644 --- a/apps/www/registry/new-york/ui/use-toast.ts +++ b/apps/www/registry/new-york/ui/use-toast.ts @@ -26,7 +26,7 @@ const actionTypes = { let count = 0 function genId() { - count = (count + 1) % Number.MAX_VALUE + count = (count + 1) % Number.MAX_SAFE_INTEGER return count.toString() }