Skip to content

Commit 9c8f89b

Browse files
Viraj-10necolas
authored andcommitted
[change] Support for React 19
* Remove 'findNodeHandle' - it can't be supported on web. * Remove legacy render and hydrate functions. Fix #2686 Close #2731
1 parent fcbe2d1 commit 9c8f89b

File tree

10 files changed

+181
-12216
lines changed

10 files changed

+181
-12216
lines changed

package-lock.json

+162-12,153
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@babel/preset-env": "^7.18.6",
3535
"@babel/preset-flow": "^7.18.6",
3636
"@babel/preset-react": "^7.18.6",
37-
"@testing-library/react": "^13.3.0",
37+
"@testing-library/react": "^16.3.0",
3838
"babel-eslint": "^10.1.0",
3939
"babel-jest": "^29.7.0",
4040
"babel-plugin-add-module-exports": "^1.0.4",

packages/benchmarks/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"classnames": "^2.3.1",
1212
"d3-scale-chromatic": "^3.0.0",
1313
"prop-types": "^15.6.0",
14-
"react": ">=17.0.2",
15-
"react-dom": ">=17.0.2",
16-
"react-native-web": "0.18.10"
14+
"react": "^19.0.0",
15+
"react-dom": "^19.0.0",
16+
"react-native-web": "0.19.13"
1717
},
1818
"devDependencies": {
1919
"babel-loader": "^8.2.5",
20-
"babel-plugin-react-native-web": "0.18.10",
20+
"babel-plugin-react-native-web": "0.19.13",
2121
"css-loader": "^6.7.1",
2222
"style-loader": "^3.3.1",
2323
"url-loader": "^4.1.1",

packages/react-native-web-docs/src/pages/docs/apis/app-registry.md

-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ If the client should hydrate server-rendered HTML.
6969
The initial props passed to the root component.
7070
{% endcall %}
7171

72-
{% call macro.prop('mode', '"concurrent" | "legacy"') %}
73-
Default is 'concurrent'. Setting to 'legacy' will make the app will behave as if it’s running React 17.
74-
{% endcall %}
75-
7672
{% call macro.prop('rootTag', 'HTMLElement') %}
7773
The native element into which the application is rendered.
7874
{% endcall %}

packages/react-native-web/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"styleq": "^0.1.3"
3333
},
3434
"peerDependencies": {
35-
"react": "^18.0.0",
36-
"react-dom": "^18.0.0"
35+
"react": "^18.0.0 || ^19.0.0",
36+
"react-dom": "^18.0.0 || ^19.0.0"
3737
},
3838
"author": "Nicolas Gallagher",
3939
"license": "MIT",

packages/react-native-web/src/exports/AppRegistry/renderApplication.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { ComponentType, Node } from 'react';
1212

1313
import AppContainer from './AppContainer';
1414
import invariant from 'fbjs/lib/invariant';
15-
import renderLegacy, { hydrateLegacy, render, hydrate } from '../render';
15+
import render, { hydrate } from '../render';
1616
import StyleSheet from '../StyleSheet';
1717
import React from 'react';
1818

@@ -27,18 +27,11 @@ export default function renderApplication<Props: Object>(
2727
options: {
2828
hydrate: boolean,
2929
initialProps: Props,
30-
mode: 'concurrent' | 'legacy',
3130
rootTag: any
3231
}
3332
): Application {
34-
const { hydrate: shouldHydrate, initialProps, mode, rootTag } = options;
35-
const renderFn = shouldHydrate
36-
? mode === 'concurrent'
37-
? hydrate
38-
: hydrateLegacy
39-
: mode === 'concurrent'
40-
? render
41-
: renderLegacy;
33+
const { hydrate: shouldHydrate, initialProps, rootTag } = options;
34+
const renderFn = shouldHydrate ? hydrate : render;
4235

4336
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
4437

packages/react-native-web/src/exports/findNodeHandle/index.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,11 @@
88
* @noflow
99
*/
1010

11-
import { findDOMNode } from 'react-dom';
12-
13-
/**
14-
* @deprecated imperatively finding the DOM element of a react component has been deprecated in React 18.
15-
* You should use ref properties on the component instead.
16-
*/
1711
const findNodeHandle = (component) => {
18-
let node;
19-
20-
try {
21-
node = findDOMNode(component);
22-
} catch (e) {}
23-
24-
return node;
12+
throw new Error(
13+
'findNodeHandle is not supported on web. ' +
14+
'Use the ref property on the component instead.'
15+
);
2516
};
2617

2718
export default findNodeHandle;

packages/react-native-web/src/exports/render/index.js

+1-26
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,21 @@
99

1010
'use client';
1111

12-
import {
13-
hydrate as domLegacyHydrate,
14-
render as domLegacyRender
15-
} from 'react-dom';
1612
import {
1713
createRoot as domCreateRoot,
1814
hydrateRoot as domHydrateRoot
1915
} from 'react-dom/client';
2016

21-
import unmountComponentAtNode from '../unmountComponentAtNode';
2217
import { createSheet } from '../StyleSheet/dom';
2318

2419
export function hydrate(element, root) {
2520
createSheet(root);
2621
return domHydrateRoot(root, element);
2722
}
2823

29-
export function render(element, root) {
24+
export default function render(element, root) {
3025
createSheet(root);
3126
const reactRoot = domCreateRoot(root);
3227
reactRoot.render(element);
3328
return reactRoot;
3429
}
35-
36-
export function hydrateLegacy(element, root, callback) {
37-
createSheet(root);
38-
domLegacyHydrate(element, root, callback);
39-
return {
40-
unmount: function () {
41-
return unmountComponentAtNode(root);
42-
}
43-
};
44-
}
45-
46-
export default function renderLegacy(element, root, callback) {
47-
createSheet(root);
48-
domLegacyRender(element, root, callback);
49-
return {
50-
unmount: function () {
51-
return unmountComponentAtNode(root);
52-
}
53-
};
54-
}

packages/react-native-web/src/exports/unmountComponentAtNode/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
* @noflow
88
*/
99

10-
import { unmountComponentAtNode } from 'react-dom';
11-
export default unmountComponentAtNode;
10+
export default function unmountComponentAtNode(rootTag) {
11+
rootTag.unmount();
12+
return true;
13+
}

packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import RefreshControl from '../../../exports/RefreshControl';
2626
import ScrollView from '../../../exports/ScrollView';
2727
import View, { type ViewProps } from '../../../exports/View';
2828
import StyleSheet from '../../../exports/StyleSheet';
29-
import findNodeHandle from '../../../exports/findNodeHandle';
3029

3130
import Batchinator from '../Batchinator';
3231
import clamp from '../Utilities/clamp';

0 commit comments

Comments
 (0)