Skip to content

Commit

Permalink
use native crypto to generate uuid
Browse files Browse the repository at this point in the history
closes #11956
  • Loading branch information
a-hariti committed Nov 26, 2024
1 parent 78c9c00 commit 5e922cd
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/components/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ import styles from './search.module.scss';
import {Logo} from '../logo';
import {NavLink} from '../navlink';

// https://stackoverflow.com/a/2117523/115146
function uuidv4() {
let dt = new Date().getTime();
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
return uuid;
}

// Initialize Algolia Insights
algoliaInsights('init', {
appId: process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
Expand All @@ -42,7 +31,7 @@ algoliaInsights('init', {
// We dont want to track anyone cross page/sessions or use cookies
// so just generate a random token each time the page is loaded and
// treat it as a random user.
const randomUserToken = uuidv4();
const randomUserToken = crypto.randomUUID();

const MAX_HITS = 10;

Expand Down

0 comments on commit 5e922cd

Please sign in to comment.