You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fields should fallback to other solution when window.crypto.randomUUID() is not available
Current Behavior
window.crypto.randomUUID is undefined
Possible Solution
Write a fallback to react useId if it's available or getRandomValues() to generate uuid like id
functiongenerateUUID(){// Check if crypto.randomUUID() is supportedif(typeofcrypto.randomUUID==="function"){returncrypto.randomUUID();}elseif(typeofReact!=="undefined"&&typeofReact.useId==="function"){// Fallback to React.useId, but keep in mind this might not generate a proper UUIDconstid=React.useId();returnid;// Return the ID as-is since React.useId doesn't guarantee a UUID format}else{// Fallback to crypto.getRandomValues()// Generate an array of 16 random bytesconstbuffer=newUint8Array(16);window.crypto.getRandomValues(buffer);// Convert the byte array to a hexadecimal stringletuuid='';for(leti=0;i<buffer.length;i++){uuid+=('00'+buffer[i].toString(16)).slice(-2);// Pad with zeros}// Replace dashes to mimic UUID v4 formatuuid=uuid.replace(/-/g,'').replace(/\b(.{6})(.{4})(.{4})(.{12})\b/,'$1-$2-$3-$4');returnuuid;}}
crypto.randomUUID() is relatively new, it was introduced 3 years ago and projects that have users with <iOS 15.3 encounter this problem. Workaround for now is to patch collect-js-react package
Your Environment
Version used: 1.1.0
Browser Name and version: Safari < 15.4
Operating System and version (desktop or mobile): Mobile and Desktop
Link to your project:
The text was updated successfully, but these errors were encountered:
Hi @marcincodes you are right iOS 15.3 and less - don't support crypto.randomUUID() from the box
we released a new version 1.2.0 and replace .randomUUID()
Expected Behavior
Fields should fallback to other solution when
window.crypto.randomUUID()
is not availableCurrent Behavior
window.crypto.randomUUID is undefined
Possible Solution
Write a fallback to react
useId
if it's available orgetRandomValues()
to generate uuid like idSource: https://www.phind.com/search?cache=u11vgs2u05g6gdllheburzal
It will be even better to use
useId
from react and fallback to other solutionsSteps to Reproduce (for bugs)
Context
crypto.randomUUID()
is relatively new, it was introduced 3 years ago and projects that have users with <iOS 15.3 encounter this problem. Workaround for now is to patch collect-js-react packageYour Environment
The text was updated successfully, but these errors were encountered: