@@ -240,13 +240,30 @@ class ReorderCell extends React.PureComponent {
240
240
contents : this . cellRef . current ,
241
241
} ;
242
242
243
- ReactDOM . render (
244
- // Since we're effectively rendering the proxy in a separate VDOM root , we cannot directly pass in our context.
245
- // To solve this, we use ExternalContextProvider to pass down the context value .
246
- // ExternalContextProvider also ensures that even if our cell gets unmounted, the dragged cell still receives updates from context.
243
+ // Since we're effectively rendering the proxy in a separate VDOM root, we cannot directly pass in our context.
244
+ // To solve this , we use ExternalContextProvider to pass down the context value .
245
+ // ExternalContextProvider also ensures that even if our cell gets unmounted, the dragged cell still receives updates from context .
246
+ const proxy = (
247
247
< ExternalContextProvider value = { this . context } >
248
248
< DragProxy { ...this . props } { ...additionalProps } />
249
- </ ExternalContextProvider > ,
249
+ </ ExternalContextProvider >
250
+ ) ;
251
+
252
+ if ( this . props . __useReactv19Root ) {
253
+ const flushSync = ReactDOM . flushSync || ( ( fn ) => fn ( ) ) ; // ReactDOM.flushSync doesn't exist in older versions of React
254
+ // flushSync is required to ensure that the drag proxy gets mounted synchronously in newer version of React
255
+ flushSync ( ( ) => {
256
+ const root = this . props . __useReactv19Root ( this . getDragContainer ( ) ) ;
257
+ this . dragContainer . root = root ;
258
+ root . render ( proxy ) ;
259
+ } ) ;
260
+ // we consider our cell to be in a reordering state as soon as the drag proxy gets mounted
261
+ this . setState ( { isReordering : true } ) ;
262
+ return ;
263
+ }
264
+
265
+ ReactDOM . render (
266
+ proxy ,
250
267
this . getDragContainer ( ) ,
251
268
// we consider our cell in a reordering state as soon as the drag proxy gets mounted
252
269
( ) => this . setState ( { isReordering : true } )
@@ -287,7 +304,11 @@ class ReorderCell extends React.PureComponent {
287
304
288
305
removeDragContainer = ( ) => {
289
306
// since the drag container is going to be removed, also unmount the drag proxy
290
- ReactDOM . unmountComponentAtNode ( this . dragContainer ) ;
307
+ if ( this . props . __useReactv19Root ) {
308
+ this . dragContainer . root . unmount ( ) ;
309
+ } else {
310
+ ReactDOM . unmountComponentAtNode ( this . dragContainer ) ;
311
+ }
291
312
292
313
this . dragContainer . remove ( ) ;
293
314
this . dragContainer = null ;
@@ -363,6 +384,25 @@ ReorderCell.propTypes = {
363
384
* ```
364
385
*/
365
386
onColumnReorderEnd : PropTypes . func . isRequired ,
387
+
388
+ /**
389
+ * HACK to make this plugin work in a React v19 environment by letting the client pass the `createRoot` function from `react-dom/client`.
390
+ *
391
+ * Example usage:
392
+ * ```
393
+ * import { createRoot } from 'react-dom/client';
394
+ *
395
+ * const reorderCell = (
396
+ * <ReorderCell
397
+ * __useReactv19Root={createRoot}
398
+ * />
399
+ * ```
400
+ *
401
+ * See https://github.com/schrodinger/fixed-data-table-2/issues/743) for more information.
402
+ *
403
+ * @deprecated This'll be removed in future major version updates of FDT.
404
+ */
405
+ __useReactv19Root : PropTypes . func ,
366
406
} ;
367
407
368
408
export default ReorderCell ;
0 commit comments