dev-utils,techdocs: add conditional support for React 18

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-13 15:31:05 +02:00
parent 070f8e2c95
commit 38cda52746
4 changed files with 13 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
In frontend builds and tests `process.env.HAS_REACT_DOM_CLIENT` will now be defined if `react-dom/client` is present, i.e. if using React 18. This allows for conditional imports of `react-dom/client`.
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/dev-utils': patch
'@backstage/plugin-techdocs': patch
---
Added support for React 18. The new `createRoot` API from `react-dom/client` will now be used if present.
+1 -4
View File
@@ -49,10 +49,7 @@ import { createRoutesFromChildren, Route } from 'react-router-dom';
import { SidebarThemeSwitcher } from './SidebarThemeSwitcher';
import 'react-dom';
let ReactDOM:
| typeof import('react-dom')
// TODO: replace with import('react-dom/client') when repo is migrated to 18
| { createRoot(el: HTMLElement): { render(el: JSX.Element): void } };
let ReactDOM: typeof import('react-dom') | typeof import('react-dom/client');
if (process.env.HAS_REACT_DOM_CLIENT) {
ReactDOM = require('react-dom/client');
} else {
@@ -14,10 +14,7 @@
* limitations under the License.
*/
let ReactDOM:
| typeof import('react-dom')
// TODO: replace with import('react-dom/client') when repo is migrated to 18
| { createRoot(el: HTMLElement): { render(el: JSX.Element): void } };
let ReactDOM: typeof import('react-dom') | typeof import('react-dom/client');
if (process.env.HAS_REACT_DOM_CLIENT) {
ReactDOM = require('react-dom/client');
} else {