From da05c44cb84dccac4d3b4f34d08ee4f815645ca2 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 9 Apr 2024 11:14:26 -0700 Subject: [PATCH] Fix cloneElement using string ref w no owner --- packages/react/src/jsx/ReactJSXElement.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react/src/jsx/ReactJSXElement.js b/packages/react/src/jsx/ReactJSXElement.js index b429db3326b5e..91d0850978668 100644 --- a/packages/react/src/jsx/ReactJSXElement.js +++ b/packages/react/src/jsx/ReactJSXElement.js @@ -870,7 +870,11 @@ export function cloneElement(element, config, children) { // Silently steal the ref from the parent. ref = config.ref; if (!disableStringRefs) { - ref = coerceStringRef(ref, owner, element.type); + let refOwner = owner; + if (refOwner == null) { + refOwner = ReactSharedInternals.owner; + } + ref = coerceStringRef(ref, refOwner, element.type); } } owner = ReactSharedInternals.owner;