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