Skip to content

Commit d9617ad

Browse files
adubrouskiAnton Dubrouski
and
Anton Dubrouski
authored
Full react 19 support (#1866)
Co-authored-by: Anton Dubrouski <anton.dubrouski@softnetix.io>
1 parent 2f6ff33 commit d9617ad

File tree

6 files changed

+72
-39
lines changed

6 files changed

+72
-39
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
"react-lifecycles-compat": "^3.0.4"
148148
},
149149
"peerDependencies": {
150-
"react": "^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0",
151-
"react-dom": "^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0"
150+
"react": "^16.3.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
151+
"react-dom": "^16.3.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
152152
},
153153
"browserify": {
154154
"transform": [

source/CellMeasurer/CellMeasurer.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @flow */
22
import * as React from 'react';
3-
import {findDOMNode} from 'react-dom';
43
import type {CellMeasureCache} from './types';
4+
import {cloneElement} from 'react';
55

66
type Children = (params: {measure: () => void}) => React.Element<*>;
77

@@ -30,7 +30,7 @@ type Props = {
3030
export default class CellMeasurer extends React.PureComponent<Props> {
3131
static __internalCellMeasurerFlag = false;
3232

33-
_child: ?Element;
33+
_child: {current: HTMLElement | null} = React.createRef();
3434

3535
componentDidMount() {
3636
this._maybeMeasureCell();
@@ -43,18 +43,31 @@ export default class CellMeasurer extends React.PureComponent<Props> {
4343
render() {
4444
const {children} = this.props;
4545

46-
return typeof children === 'function'
47-
? children({
48-
measure: this._measure,
49-
registerChild: this._registerChild,
50-
})
51-
: children;
46+
const resolvedChildren =
47+
typeof children === 'function'
48+
? children({measure: this._measure, registerChild: this._registerChild})
49+
: children;
50+
51+
if (resolvedChildren === null) {
52+
return resolvedChildren;
53+
}
54+
55+
return cloneElement(resolvedChildren, {
56+
ref: node => {
57+
if (typeof resolvedChildren.ref === 'function') {
58+
resolvedChildren.ref(node);
59+
} else if (resolvedChildren.ref) {
60+
resolvedChildren.ref.current = node;
61+
}
62+
this._child.current = node;
63+
},
64+
});
5265
}
5366

5467
_getCellMeasurements() {
5568
const {cache} = this.props;
5669

57-
const node = this._child || findDOMNode(this);
70+
const node = this._child.current;
5871

5972
// TODO Check for a bad combination of fixedWidth and missing numeric width or vice versa with height
6073

@@ -157,7 +170,7 @@ export default class CellMeasurer extends React.PureComponent<Props> {
157170
'CellMeasurer registerChild expects to be passed Element or null',
158171
);
159172
}
160-
this._child = element;
173+
this._child.current = element;
161174
if (element) {
162175
this._maybeMeasureCell();
163176
}

source/Grid/Grid.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ type Props = {
221221

222222
/** Width of Grid; this property determines the number of visible (vs virtualized) columns. */
223223
width: number,
224+
225+
/** Reference to DOM node */
226+
elementRef?: React.Ref<React.ElementType>,
224227
};
225228

226229
type InstanceProps = {
@@ -1382,6 +1385,12 @@ class Grid extends React.PureComponent<Props, State> {
13821385

13831386
_setScrollingContainerRef = (ref: Element) => {
13841387
this._scrollingContainer = ref;
1388+
1389+
if (typeof this.props.elementRef === 'function') {
1390+
this.props.elementRef(ref);
1391+
} else if (typeof this.props.elementRef === 'object') {
1392+
this.props.elementRef.current = ref;
1393+
}
13851394
};
13861395

13871396
/**

source/Table/Table.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import clsx from 'clsx';
66
import Column from './Column';
77
import PropTypes from 'prop-types';
88
import * as React from 'react';
9-
import {findDOMNode} from 'react-dom';
109
import Grid, {accessibilityOverscanIndicesGetter} from '../Grid';
1110

1211
import defaultRowRenderer from './defaultRowRenderer';
@@ -263,6 +262,7 @@ export default class Table extends React.PureComponent {
263262
this._onScroll = this._onScroll.bind(this);
264263
this._onSectionRendered = this._onSectionRendered.bind(this);
265264
this._setRef = this._setRef.bind(this);
265+
this._setGridElementRef = this._setGridElementRef.bind(this);
266266
}
267267

268268
forceUpdateGrid() {
@@ -338,8 +338,8 @@ export default class Table extends React.PureComponent {
338338
}
339339

340340
getScrollbarWidth() {
341-
if (this.Grid) {
342-
const Grid = findDOMNode(this.Grid);
341+
if (this.GridElement) {
342+
const Grid = this.GridElement;
343343
const clientWidth = Grid.clientWidth || 0;
344344
const offsetWidth = Grid.offsetWidth || 0;
345345
return offsetWidth - clientWidth;
@@ -390,7 +390,7 @@ export default class Table extends React.PureComponent {
390390
React.Children.toArray(children).forEach((column, index) => {
391391
const flexStyles = this._getFlexStyleForColumn(
392392
column,
393-
column.props.style,
393+
column.props.style || Column.defaultProps.style,
394394
);
395395

396396
this._cachedColumnStyles[index] = {
@@ -427,6 +427,7 @@ export default class Table extends React.PureComponent {
427427

428428
<Grid
429429
{...this.props}
430+
elementRef={this._setGridElementRef}
430431
aria-readonly={null}
431432
autoContainerWidth
432433
className={clsx('ReactVirtualized__Table__Grid', gridClassName)}
@@ -734,6 +735,10 @@ export default class Table extends React.PureComponent {
734735
this.Grid = ref;
735736
}
736737

738+
_setGridElementRef(ref) {
739+
this.GridElement = ref;
740+
}
741+
737742
_setScrollbarWidth() {
738743
const scrollbarWidth = this.getScrollbarWidth();
739744

source/WindowScroller/WindowScroller.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow
22

33
import * as React from 'react';
4-
import * as ReactDOM from 'react-dom';
54
import {
65
registerScrollListener,
76
unregisterScrollListener,
@@ -91,6 +90,7 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
9190
_positionFromLeft = 0;
9291
_detectElementResize: DetectElementResize;
9392
_child: ?Element;
93+
_windowScrollerRef: {current: HTMLElement | null} = React.createRef();
9494

9595
state = {
9696
...getDimensions(this.props.scrollElement, this.props),
@@ -103,7 +103,7 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
103103
const {onResize} = this.props;
104104
const {height, width} = this.state;
105105

106-
const thisNode = this._child || ReactDOM.findDOMNode(this);
106+
const thisNode = this._child || this._windowScrollerRef.current;
107107
if (thisNode instanceof Element && scrollElement) {
108108
const offset = getPositionOffset(thisNode, scrollElement);
109109
this._positionFromTop = offset.top;
@@ -176,15 +176,21 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
176176
const {children} = this.props;
177177
const {isScrolling, scrollTop, scrollLeft, height, width} = this.state;
178178

179-
return children({
180-
onChildScroll: this._onChildScroll,
181-
registerChild: this._registerChild,
182-
height,
183-
isScrolling,
184-
scrollLeft,
185-
scrollTop,
186-
width,
187-
});
179+
return React.createElement(
180+
'div',
181+
{
182+
ref: this._windowScrollerRef,
183+
},
184+
children({
185+
onChildScroll: this._onChildScroll,
186+
registerChild: this._registerChild,
187+
height,
188+
isScrolling,
189+
scrollLeft,
190+
scrollTop,
191+
width,
192+
}),
193+
);
188194
}
189195

190196
_registerChild = element => {

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
"@babel/generator@^7.12.13":
4949
version "7.13.16"
50-
resolved "https://registry.nlark.com/@babel/generator/download/@babel/generator-7.13.16.tgz#0befc287031a201d84cdfc173b46b320ae472d14"
51-
integrity sha1-C+/ChwMaIB2EzfwXO0azIK5HLRQ=
50+
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.13.16.tgz#0befc287031a201d84cdfc173b46b320ae472d14"
51+
integrity sha512-grBBR75UnKOcUWMp8WoDxNsWCFl//XCK6HWTrBQKTr5SV9f5g0pNOjdyzi/DTBv12S9GnYPInIXQBTky7OXEMg==
5252
dependencies:
5353
"@babel/types" "^7.13.16"
5454
jsesc "^2.5.1"
@@ -196,8 +196,8 @@
196196

197197
"@babel/helper-plugin-utils@^7.12.13":
198198
version "7.13.0"
199-
resolved "https://registry.npm.taobao.org/@babel/helper-plugin-utils/download/@babel/helper-plugin-utils-7.13.0.tgz#806526ce125aed03373bc416a828321e3a6a33af"
200-
integrity sha1-gGUmzhJa7QM3O8QWqCgyHjpqM68=
199+
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.13.0.tgz#806526ce125aed03373bc416a828321e3a6a33af"
200+
integrity sha512-ZPafIPSwzUlAoWT8DKs1W2VyF2gOWthGd5NGFMsBcMMol+ZhK+EQY/e6V96poa6PA/Bh+C9plWN0hXO1uB8AfQ==
201201

202202
"@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4":
203203
version "7.5.5"
@@ -244,8 +244,8 @@
244244

245245
"@babel/helper-validator-identifier@^7.12.11":
246246
version "7.12.11"
247-
resolved "https://registry.nlark.com/@babel/helper-validator-identifier/download/@babel/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
248-
integrity sha1-yaHwIZF9y1zPDU5FPjmQIpgfye0=
247+
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
248+
integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==
249249

250250
"@babel/helper-wrap-function@^7.7.0":
251251
version "7.7.0"
@@ -360,8 +360,8 @@
360360

361361
"@babel/plugin-syntax-flow@^7.12.13":
362362
version "7.12.13"
363-
resolved "https://registry.npm.taobao.org/@babel/plugin-syntax-flow/download/@babel/plugin-syntax-flow-7.12.13.tgz#5df9962503c0a9c918381c929d51d4d6949e7e86"
364-
integrity sha1-XfmWJQPAqckYOBySnVHU1pSefoY=
363+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.12.13.tgz#5df9962503c0a9c918381c929d51d4d6949e7e86"
364+
integrity sha512-J/RYxnlSLXZLVR7wTRsozxKT8qbsx1mNKJzXEEjQ0Kjx1ZACcyHgbanNWNCFtc36IzuWhYWPpvJFFoexoOWFmA==
365365
dependencies:
366366
"@babel/helper-plugin-utils" "^7.12.13"
367367

@@ -491,8 +491,8 @@
491491

492492
"@babel/plugin-transform-flow-comments@^7.12.13":
493493
version "7.12.13"
494-
resolved "https://registry.nlark.com/@babel/plugin-transform-flow-comments/download/@babel/plugin-transform-flow-comments-7.12.13.tgz#b6f0de89ac4955572913f4af82f6b8ddbff38bf1"
495-
integrity sha1-tvDeiaxJVVcpE/Svgva43b/zi/E=
494+
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-flow-comments/-/plugin-transform-flow-comments-7.12.13.tgz#b6f0de89ac4955572913f4af82f6b8ddbff38bf1"
495+
integrity sha512-o4Z7Mw9KvrfAxBwSr+Ia+E0+LLb6ZzDXQTsJb628ejXuvvNoCDyu3FLBcz2/W8B7q/MOzm6d6pbNM6ur/aegMQ==
496496
dependencies:
497497
"@babel/generator" "^7.12.13"
498498
"@babel/helper-plugin-utils" "^7.12.13"
@@ -848,8 +848,8 @@
848848

849849
"@babel/types@^7.13.16":
850850
version "7.13.17"
851-
resolved "https://registry.nlark.com/@babel/types/download/@babel/types-7.13.17.tgz#48010a115c9fba7588b4437dd68c9469012b38b4"
852-
integrity sha1-SAEKEVyfunWItEN91oyUaQErOLQ=
851+
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.13.17.tgz#48010a115c9fba7588b4437dd68c9469012b38b4"
852+
integrity sha512-RawydLgxbOPDlTLJNtoIypwdmAy//uQIzlKt2+iBiJaRlVuI6QLUxVAyWGNfOzp8Yu4L4lLIacoCyTNtpb4wiA==
853853
dependencies:
854854
"@babel/helper-validator-identifier" "^7.12.11"
855855
to-fast-properties "^2.0.0"

0 commit comments

Comments
 (0)