-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React 18 conditional support #1449
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ReactDOM from 'react-dom'; | ||
import type { RootRenderFunction, RootHydrateFunction } from '../types'; | ||
|
||
export const canHydrate = !!ReactDOM.hydrate | ||
|
||
export const hydrate: RootHydrateFunction = (domNode, reactElement) => { | ||
return ReactDOM.hydrate(reactElement, domNode) | ||
} | ||
|
||
export const render: RootRenderFunction = (domNode, reactElement) => { | ||
return ReactDOM.render(reactElement, domNode); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @ts-expect-error react-dom/client only available in React 18 | ||
// eslint-disable-next-line import/no-unresolved | ||
import ReactDOM from 'react-dom/client'; | ||
import type { RootRenderFunction, RootHydrateFunction } from '../types'; | ||
|
||
export const canHydrate = !!ReactDOM.hydrateRoot; | ||
|
||
export const hydrate: RootHydrateFunction = (domNode, reactElement) => ReactDOM.hydrateRoot(domNode, reactElement); | ||
|
||
export const render: RootRenderFunction = (domNode, reactElement) => { | ||
const root = ReactDOM.createRoot(domNode); | ||
root.render(reactElement); | ||
return root; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import supportsReactCreateRoot from './supportsReactCreateRoot'; | ||
import * as legacyRootHandler from './legacyRootHandler'; | ||
import * as modernRootHandler from './modernRootHandler'; | ||
|
||
|
||
let toExport; | ||
|
||
if (supportsReactCreateRoot) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be good based not only on React version but also some configuration option so it's an opt-in |
||
toExport = legacyRootHandler; | ||
} else { | ||
toExport = modernRootHandler; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Struggling to find a nicer way to get this going, can't think of a way to do a dynamic import and then reexport There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be fairly trivial with top-level await though 🤔 |
||
|
||
export const { | ||
canHydrate, | ||
hydrate: reactHydrate, | ||
render: reactRender | ||
} = toExport; | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unmountComponentAtNode
is considered legacy https://reactjs.org/docs/react-dom.html#unmountcomponentatnode but would need to store references to root instead if we were to updateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #1466.