From 57ee25decf706c16cf59971c208c91ae3f794be6 Mon Sep 17 00:00:00 2001 From: bdbch Date: Wed, 4 Jun 2025 12:52:52 +0200 Subject: [PATCH] cloned react renderer element props to avoid side effects --- packages/react/src/ReactRenderer.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react/src/ReactRenderer.tsx b/packages/react/src/ReactRenderer.tsx index f93ad7568..39e56e7c9 100644 --- a/packages/react/src/ReactRenderer.tsx +++ b/packages/react/src/ReactRenderer.tsx @@ -153,17 +153,19 @@ export class ReactRenderer = object> const isClassComp = isClassComponent(Component) const isForwardRefComp = isForwardRefComponent(Component) - if (!props.ref) { + const elementProps = { ...props } + + if (!elementProps.ref) { if (isReact19) { // React 19: ref is a standard prop for all components // @ts-ignore - Setting ref prop for React 19 compatibility - props.ref = (ref: R) => { + elementProps.ref = (ref: R) => { this.ref = ref } } else if (isClassComp || isForwardRefComp) { // React 18 and prior: only set ref for class components and forwardRef components // @ts-ignore - Setting ref prop for React 18 class/forwardRef components - props.ref = (ref: R) => { + elementProps.ref = (ref: R) => { this.ref = ref } } @@ -171,7 +173,7 @@ export class ReactRenderer = object> // This is a limitation we have to accept for React 18 function components without forwardRef } - this.reactElement = + this.reactElement = editor?.contentComponent?.setRenderer(this.id, this) }