Skip to content

Commit

Permalink
Use crypto.randomUUID() instead of uuid module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikeee committed Dec 6, 2024
1 parent 75260b8 commit 98ae999
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions src/core/Cloud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -246,7 +245,7 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef<Group, CloudProps>

const parent = React.useContext(context)
const ref = React.useRef<Group>(null!)
const [uuid] = React.useState(() => v4())
const [uuid] = React.useState(() => crypto.randomUUID())
const clouds: CloudState[] = React.useMemo(() => {
return [...new Array(segments)].map(
(_, index) =>
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 98ae999

Please sign in to comment.