@tiptap/react 2.13.0 → 2.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1208,9 +1208,46 @@ function isClassComponent(Component) {
1208
1208
  * @returns {boolean}
1209
1209
  */
1210
1210
  function isForwardRefComponent(Component) {
1211
- var _a;
1212
1211
  return !!(typeof Component === 'object'
1213
- && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
1212
+ && Component.$$typeof
1213
+ && (Component.$$typeof.toString() === 'Symbol(react.forward_ref)'
1214
+ || Component.$$typeof.description === 'react.forward_ref'));
1215
+ }
1216
+ /**
1217
+ * Check if a component is a memoized component.
1218
+ * @param Component
1219
+ * @returns {boolean}
1220
+ */
1221
+ function isMemoComponent(Component) {
1222
+ return !!(typeof Component === 'object'
1223
+ && Component.$$typeof
1224
+ && (Component.$$typeof.toString() === 'Symbol(react.memo)' || Component.$$typeof.description === 'react.memo'));
1225
+ }
1226
+ /**
1227
+ * Check if a component can safely receive a ref prop.
1228
+ * This includes class components, forwardRef components, and memoized components
1229
+ * that wrap forwardRef or class components.
1230
+ * @param Component
1231
+ * @returns {boolean}
1232
+ */
1233
+ function canReceiveRef(Component) {
1234
+ // Check if it's a class component
1235
+ if (isClassComponent(Component)) {
1236
+ return true;
1237
+ }
1238
+ // Check if it's a forwardRef component
1239
+ if (isForwardRefComponent(Component)) {
1240
+ return true;
1241
+ }
1242
+ // Check if it's a memoized component
1243
+ if (isMemoComponent(Component)) {
1244
+ // For memoized components, check the wrapped component
1245
+ const wrappedComponent = Component.type;
1246
+ if (wrappedComponent) {
1247
+ return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent);
1248
+ }
1249
+ }
1250
+ return false;
1214
1251
  }
1215
1252
  /**
1216
1253
  * Check if we're running React 19+ by detecting if function components support ref props
@@ -1279,26 +1316,18 @@ class ReactRenderer {
1279
1316
  const editor = this.editor;
1280
1317
  // Handle ref forwarding with React 18/19 compatibility
1281
1318
  const isReact19 = isReact19Plus();
1282
- const isClassComp = isClassComponent(Component);
1283
- const isForwardRefComp = isForwardRefComponent(Component);
1319
+ const componentCanReceiveRef = canReceiveRef(Component);
1284
1320
  const elementProps = { ...props };
1285
- if (!elementProps.ref) {
1286
- if (isReact19) {
1287
- // React 19: ref is a standard prop for all components
1288
- // @ts-ignore - Setting ref prop for React 19 compatibility
1289
- elementProps.ref = (ref) => {
1290
- this.ref = ref;
1291
- };
1292
- }
1293
- else if (isClassComp || isForwardRefComp) {
1294
- // React 18 and prior: only set ref for class components and forwardRef components
1295
- // @ts-ignore - Setting ref prop for React 18 class/forwardRef components
1296
- elementProps.ref = (ref) => {
1297
- this.ref = ref;
1298
- };
1299
- }
1300
- // For function components in React 18, we can't use ref - the component won't receive it
1301
- // This is a limitation we have to accept for React 18 function components without forwardRef
1321
+ // Always remove ref if the component cannot receive it (unless React 19+)
1322
+ if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) {
1323
+ delete elementProps.ref;
1324
+ }
1325
+ // Only assign our own ref if allowed
1326
+ if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) {
1327
+ // @ts-ignore - Setting ref prop for compatible components
1328
+ elementProps.ref = (ref) => {
1329
+ this.ref = ref;
1330
+ };
1302
1331
  }
1303
1332
  this.reactElement = React.createElement(Component, { ...elementProps });
1304
1333
  (_a = editor === null || editor === void 0 ? void 0 : editor.contentComponent) === null || _a === void 0 ? void 0 : _a.setRenderer(this.id, this);