Skip to content

Commit 5e922cd

Browse files
committed
use native crypto to generate uuid
closes #11956
1 parent 78c9c00 commit 5e922cd

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

src/components/search/index.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ import styles from './search.module.scss';
2222
import {Logo} from '../logo';
2323
import {NavLink} from '../navlink';
2424

25-
// https://stackoverflow.com/a/2117523/115146
26-
function uuidv4() {
27-
let dt = new Date().getTime();
28-
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
29-
const r = (dt + Math.random() * 16) % 16 | 0;
30-
dt = Math.floor(dt / 16);
31-
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
32-
});
33-
return uuid;
34-
}
35-
3625
// Initialize Algolia Insights
3726
algoliaInsights('init', {
3827
appId: process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
@@ -42,7 +31,7 @@ algoliaInsights('init', {
4231
// We dont want to track anyone cross page/sessions or use cookies
4332
// so just generate a random token each time the page is loaded and
4433
// treat it as a random user.
45-
const randomUserToken = uuidv4();
34+
const randomUserToken = crypto.randomUUID();
4635

4736
const MAX_HITS = 10;
4837

0 commit comments

Comments
 (0)