From 98ae9994b9ba46c042ec2364125d911e72dde37d Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Fri, 6 Dec 2024 01:08:05 +0100 Subject: [PATCH 1/2] Use `crypto.randomUUID()` instead of `uuid` module The `crypto` global is available in all supported Node.js versions as well as [in all major browsers](https://caniuse.com/mdn-api_crypto_randomuuid). The uuid module is rendered unnecessary for uuidv4. `@react-three/drei` is currently downloaded about 253000 times per week, so about 13409000 times per year. `uuid@9` is about 3.7 kB in size (gzipped+minified). Removing this dependency saves about 50GB traffic per year. --- package.json | 1 - src/core/Cloud.tsx | 3 +-- yarn.lock | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 33f674e3c..5887d2a49 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "troika-three-text": "^0.52.0", "tunnel-rat": "^0.1.2", "utility-types": "^3.11.0", - "uuid": "^9.0.1", "zustand": "^5.0.1" }, "devDependencies": { diff --git a/src/core/Cloud.tsx b/src/core/Cloud.tsx index bf53cac89..07c0f36d2 100644 --- a/src/core/Cloud.tsx +++ b/src/core/Cloud.tsx @@ -15,7 +15,6 @@ import { } from 'three' import { MaterialNode, extend, applyProps, useFrame, ReactThreeFiber } from '@react-three/fiber' import { useTexture } from './Texture' -import { v4 } from 'uuid' import { setUpdateRange } from '../helpers/deprecated' declare global { @@ -246,7 +245,7 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef const parent = React.useContext(context) const ref = React.useRef(null!) - const [uuid] = React.useState(() => v4()) + const [uuid] = React.useState(() => crypto.randomUUID()) const clouds: CloudState[] = React.useMemo(() => { return [...new Array(segments)].map( (_, index) => diff --git a/yarn.lock b/yarn.lock index b2c83c873..b5defaa41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2902,7 +2902,6 @@ __metadata: tunnel-rat: "npm:^0.1.2" typescript: "npm:^5.6.3" utility-types: "npm:^3.11.0" - uuid: "npm:^9.0.1" vite: "npm:^5.4.11" vite-plugin-glslify: "npm:^2.1.0" zustand: "npm:^5.0.1" @@ -12871,7 +12870,7 @@ __metadata: languageName: node linkType: hard -"uuid@npm:^9.0.0, uuid@npm:^9.0.1": +"uuid@npm:^9.0.0": version: 9.0.1 resolution: "uuid@npm:9.0.1" bin: From 1bf08c40477736cdb41d98c996e9a330838caffa Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Sun, 8 Dec 2024 15:55:12 +0100 Subject: [PATCH 2/2] chore: Use useId instead of UUID --- src/core/Cloud.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Cloud.tsx b/src/core/Cloud.tsx index 07c0f36d2..e6038f61d 100644 --- a/src/core/Cloud.tsx +++ b/src/core/Cloud.tsx @@ -245,7 +245,7 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef const parent = React.useContext(context) const ref = React.useRef(null!) - const [uuid] = React.useState(() => crypto.randomUUID()) + const uuid = React.useId() const clouds: CloudState[] = React.useMemo(() => { return [...new Array(segments)].map( (_, index) =>