diff --git a/.eslintrc b/.eslintrc index 000777317..c72a17076 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,7 @@ overrides: rules: "@typescript-eslint/no-namespace": 0 "@typescript-eslint/no-shadow": ["error"] + "@typescript-eslint/no-var-requires": 0 rules: no-shadow: 0 diff --git a/node_package/src/reactHydrate.ts b/node_package/src/reactHydrate.ts index 5b92b9ca2..c12fb504c 100644 --- a/node_package/src/reactHydrate.ts +++ b/node_package/src/reactHydrate.ts @@ -1,10 +1,11 @@ -import ReactDOM from 'react-dom'; import { ReactElement, Component } from 'react'; import supportsReactCreateRoot from './supportsReactCreateRoot'; +// eslint-disable-next-line import/no-dynamic-require +const ReactDOM = require(`react-dom${supportsReactCreateRoot ? '/client' : ''}`); + export default function reactHydrate(domNode: Element, reactElement: ReactElement): void | Element | Component { if (supportsReactCreateRoot) { - // @ts-expect-error potentially present if React 18 or greater return ReactDOM.hydrateRoot(domNode, reactElement); } diff --git a/node_package/src/reactRender.ts b/node_package/src/reactRender.ts index 36a57c330..5d8ebedbb 100644 --- a/node_package/src/reactRender.ts +++ b/node_package/src/reactRender.ts @@ -1,10 +1,11 @@ -import ReactDOM from 'react-dom'; import { ReactElement, Component } from 'react'; import supportsReactCreateRoot from './supportsReactCreateRoot'; +// eslint-disable-next-line import/no-dynamic-require +const ReactDOM = require(`react-dom${supportsReactCreateRoot ? '/client' : ''}`); + export default function reactRender(domNode: Element, reactElement: ReactElement): void | Element | Component { if (supportsReactCreateRoot) { - // @ts-expect-error potentially present if React 18 or greater const root = ReactDOM.createRoot(domNode); root.render(reactElement); return root