mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
cloned react renderer element props to avoid side effects
This commit is contained in:
parent
17a32a9078
commit
57ee25decf
@ -153,17 +153,19 @@ export class ReactRenderer<R = unknown, P extends Record<string, any> = object>
|
|||||||
const isClassComp = isClassComponent(Component)
|
const isClassComp = isClassComponent(Component)
|
||||||
const isForwardRefComp = isForwardRefComponent(Component)
|
const isForwardRefComp = isForwardRefComponent(Component)
|
||||||
|
|
||||||
if (!props.ref) {
|
const elementProps = { ...props }
|
||||||
|
|
||||||
|
if (!elementProps.ref) {
|
||||||
if (isReact19) {
|
if (isReact19) {
|
||||||
// React 19: ref is a standard prop for all components
|
// React 19: ref is a standard prop for all components
|
||||||
// @ts-ignore - Setting ref prop for React 19 compatibility
|
// @ts-ignore - Setting ref prop for React 19 compatibility
|
||||||
props.ref = (ref: R) => {
|
elementProps.ref = (ref: R) => {
|
||||||
this.ref = ref
|
this.ref = ref
|
||||||
}
|
}
|
||||||
} else if (isClassComp || isForwardRefComp) {
|
} else if (isClassComp || isForwardRefComp) {
|
||||||
// React 18 and prior: only set ref for class components and forwardRef components
|
// React 18 and prior: only set ref for class components and forwardRef components
|
||||||
// @ts-ignore - Setting ref prop for React 18 class/forwardRef components
|
// @ts-ignore - Setting ref prop for React 18 class/forwardRef components
|
||||||
props.ref = (ref: R) => {
|
elementProps.ref = (ref: R) => {
|
||||||
this.ref = ref
|
this.ref = ref
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +173,7 @@ export class ReactRenderer<R = unknown, P extends Record<string, any> = object>
|
|||||||
// This is a limitation we have to accept for React 18 function components without forwardRef
|
// This is a limitation we have to accept for React 18 function components without forwardRef
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reactElement = <Component {...props} />
|
this.reactElement = <Component {...elementProps} />
|
||||||
|
|
||||||
editor?.contentComponent?.setRenderer(this.id, this)
|
editor?.contentComponent?.setRenderer(this.id, this)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user