From 8722718c7bf3691a7fa434220c242fb3a3c56717 Mon Sep 17 00:00:00 2001 From: Paul Aderoju Date: Tue, 15 Sep 2026 23:07:09 +0100 Subject: [PATCH] fix: prevent TypeError when open() called before widget script loads invokeInstanceMethod used widget?.current[method] which only guards against widget being undefined. widget is a React ref and is always defined, so the optional chaining was ineffective. If the Cloudinary script hasn't loaded yet, createWidget() returns undefined, leaving widget.current undefined, and widget.current[method] throws a TypeError. Change to widget.current?.[method] so the optional chaining correctly guards against widget.current being undefined. Fixes #586. --- .../src/components/CldUploadWidget/CldUploadWidget.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next-cloudinary/src/components/CldUploadWidget/CldUploadWidget.tsx b/next-cloudinary/src/components/CldUploadWidget/CldUploadWidget.tsx index 58b86ed7..3bb264b2 100644 --- a/next-cloudinary/src/components/CldUploadWidget/CldUploadWidget.tsx +++ b/next-cloudinary/src/components/CldUploadWidget/CldUploadWidget.tsx @@ -176,7 +176,7 @@ const CldUploadWidget = ({ widget.current = createWidget(); } - if (typeof widget?.current[method] === "function") { + if (typeof widget.current?.[method] === "function") { return widget.current[method](...options); } }