File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
next-cloudinary/src/components/CldUploadWidget Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ import {
2323
2424import { getCloudinaryConfig } from "../../lib/cloudinary" ;
2525
26+ // Stable ID hook supporting React < 18 fallback
27+ const useStableId = ( ) => {
28+ if ( typeof ( React as any ) . useId === 'function' ) {
29+ return ( React as any ) . useId ( ) . replace ( / : / g, '' ) ;
30+ }
31+ return React . useRef ( `id-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) } ` ) . current ;
32+ } ;
33+
2634const CldUploadWidget = ( {
2735 children,
2836 config,
@@ -34,6 +42,7 @@ const CldUploadWidget = ({
3442 uploadPreset,
3543 ...props
3644} : CldUploadWidgetProps ) => {
45+ const uniqueId = useStableId ( ) ;
3746 const cloudinary : CldUploadWidgetCloudinaryInstance = useRef ( ) ;
3847 const widget : CldUploadWidgetWidgetInstance = useRef ( ) ;
3948
@@ -239,7 +248,7 @@ const CldUploadWidget = ({
239248 ...instanceMethods ,
240249 } ) }
241250 < Script
242- id = { `cloudinary-uploadwidget-${ Math . floor ( Math . random ( ) * 100 ) } ` }
251+ id = { `cloudinary-uploadwidget-${ uniqueId } ` }
243252 src = "https://upload-widget.cloudinary.com/global/all.js"
244253 onLoad = { handleOnLoad }
245254 onError = { ( e ) => console . error ( `Failed to load Cloudinary Upload Widget: ${ e . message } ` ) }
You can’t perform that action at this time.
0 commit comments