Skip to content

Commit 15f2af1

Browse files
committed
Add support for React 18
1 parent a5fe8fa commit 15f2af1

File tree

7 files changed

+39
-33
lines changed

7 files changed

+39
-33
lines changed

packages/documentation-framework/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ We publish this theme [on npm.](https://www.npmjs.com/package/@patternfly/docume
2828
This should not be needed, but if you encounter errors installing the above devDependencies, try adding one or more of these resolutions to your package.json file:
2929
```
3030
"resolutions": {
31-
"@types/react": "^16.8.0",
32-
"@types/react-dom": "^16.8.0",
33-
"react": "16.8.0",
34-
"react-dom": "16.8.0",
31+
"@types/react": "^18",
32+
"@types/react-dom": "^18",
33+
"react": "^18",
34+
"react-dom": "^18",
3535
"chromedriver": "102.0.0",
3636
"node-sass": "7.0.1",
3737
"puppeteer": "14.3.0",

packages/documentation-framework/app.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import { createRoot, hydrateRoot } from 'react-dom/client';
33
import { Router, useLocation } from '@reach/router';
44
import 'client-styles'; // Webpack replaces this import: patternfly-docs.css.js
55
import { SideNavLayout } from '@patternfly/documentation-framework/layouts';
@@ -107,8 +107,15 @@ const isPrerender = process.env.PRERENDER;
107107
// Don't use ReactDOM in SSR
108108
if (!isPrerender) {
109109
function render() {
110-
const renderFn = isProd ? ReactDOM.hydrate : ReactDOM.render;
111-
renderFn(<App />, document.getElementById('root'));
110+
const container = document.getElementById('root');
111+
// TODO: Enable StrictMode: https://reactjs.org/docs/strict-mode.html
112+
const app = <App />;
113+
114+
if (isProd) {
115+
hydrateRoot(container, app);
116+
} else {
117+
createRoot(container).render(app);
118+
}
112119
}
113120
// On first load, await promise for the current page to avoid flashing a "Loading..." state
114121
const Component = getAsyncComponent(null);

packages/documentation-framework/helpers/codesandbox.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,16 @@ function getReactParams(title, code, scope, lang, relativeImports) {
179179
</html>`,
180180
},
181181
[lang === 'ts' ? 'index.tsx' : 'index.js']: {
182-
content: `import ReactDOM from 'react-dom';
182+
content: `import { StrictMode } from "react";
183+
import { createRoot } from "react-dom/client";
183184
import "@patternfly/react-core/dist/styles/base.css";
184185
import './fonts.css';
185186
186187
${code}
187188
188-
const rootElement = document.getElementById("root");
189-
ReactDOM.render(<${toRender} />, rootElement);`
189+
const container = document.getElementById("root");
190+
const root = createRoot(container);
191+
root.render(<StrictMode><${toRender} /></StrictMode>);`
190192
},
191193
'fonts.css': {
192194
content: overpass
@@ -195,8 +197,8 @@ ReactDOM.render(<${toRender} />, rootElement);`
195197
content: {
196198
dependencies: {
197199
...dependencies,
198-
'react': '^16.8.0',
199-
'react-dom': '^16.8.0'
200+
'react': '^18',
201+
'react-dom': '^18'
200202
}
201203
},
202204
},

packages/documentation-framework/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"@patternfly/react-code-editor": ">=4.43.16",
8383
"@patternfly/react-core": ">=4.202.16",
8484
"@patternfly/react-table": ">=4.71.16",
85-
"react": "^16.8.0 || ^17.0.0",
86-
"react-dom": "^16.8.0 || ^17.0.0"
85+
"react": "^16.8 || ^17 || ^18",
86+
"react-dom": "^16.8 || ^17 || ^18"
8787
}
8888
}

packages/documentation-framework/scripts/webpack/webpack.server.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const serverConfig = () => {
1212
target: 'node', // Load chunks using require
1313
plugins: [
1414
new webpack.DefinePlugin({
15-
'process.env.PRERENDER': true // In app.js don't call ReactDOM.render
15+
'process.env.PRERENDER': true // In app.js don't call render
1616
}),
1717
],
1818
optimization: {

packages/v4/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"@patternfly/documentation-framework": "^1.2.27",
2121
"@patternfly/quickstarts": "^2.2.4",
2222
"@patternfly/react-docs": "5.100.1",
23-
"react": "^16.8.0 || ^17.0.0",
24-
"react-dom": "^16.8.0 || ^17.0.0"
23+
"react": "^16.8 || ^17 || ^18",
24+
"react-dom": "^16.8 || ^17 || ^18"
2525
},
2626
"devDependencies": {
2727
"@patternfly/patternfly-a11y": "4.3.0",

yarn.lock

+13-16
Original file line numberDiff line numberDiff line change
@@ -11242,14 +11242,13 @@ [email protected]:
1124211242
node-dir "^0.1.10"
1124311243
strip-indent "^3.0.0"
1124411244

11245-
"react-dom@^16.8.0 || ^17.0.0":
11246-
version "17.0.2"
11247-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
11248-
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
11245+
"react-dom@^16.8 || ^17 || ^18":
11246+
version "18.2.0"
11247+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
11248+
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
1124911249
dependencies:
1125011250
loose-envify "^1.1.0"
11251-
object-assign "^4.1.1"
11252-
scheduler "^0.20.2"
11251+
scheduler "^0.23.0"
1125311252

1125411253
1125511254
version "9.0.0"
@@ -11317,13 +11316,12 @@ react-virtualized@^9.21.1:
1131711316
prop-types "^15.7.2"
1131811317
react-lifecycles-compat "^3.0.4"
1131911318

11320-
"react@^16.8.0 || ^17.0.0":
11321-
version "17.0.2"
11322-
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
11323-
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
11319+
"react@^16.8 || ^17 || ^18":
11320+
version "18.2.0"
11321+
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
11322+
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
1132411323
dependencies:
1132511324
loose-envify "^1.1.0"
11326-
object-assign "^4.1.1"
1132711325

1132811326
read-cmd-shim@^1.0.1:
1132911327
version "1.0.5"
@@ -11985,13 +11983,12 @@ sax@^1.2.1:
1198511983
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
1198611984
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
1198711985

11988-
scheduler@^0.20.2:
11989-
version "0.20.2"
11990-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
11991-
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
11986+
scheduler@^0.23.0:
11987+
version "0.23.0"
11988+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
11989+
integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==
1199211990
dependencies:
1199311991
loose-envify "^1.1.0"
11994-
object-assign "^4.1.1"
1199511992

1199611993
schema-utils@^1.0.0:
1199711994
version "1.0.0"

0 commit comments

Comments
 (0)