mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-22 23:39:45 +00:00
Use uuid for dom widget id (#2947)
This commit is contained in:
@@ -316,10 +316,25 @@ export const paramsToCacheKey = (params: unknown): string => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random 4-character string to use as a unique suffix
|
||||
* Generates a RFC4122 compliant UUID v4 using the native crypto API when available
|
||||
* @returns A properly formatted UUID string
|
||||
*/
|
||||
export const generateRandomSuffix = (): string =>
|
||||
Math.random().toString(36).substring(2, 6)
|
||||
export const generateUUID = (): string => {
|
||||
// Use native crypto.randomUUID() if available (modern browsers)
|
||||
if (
|
||||
typeof crypto !== 'undefined' &&
|
||||
typeof crypto.randomUUID === 'function'
|
||||
) {
|
||||
return crypto.randomUUID()
|
||||
}
|
||||
|
||||
// Fallback implementation for older browsers
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0
|
||||
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
||||
return v.toString(16)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number to a locale-specific string
|
||||
|
||||
Reference in New Issue
Block a user