Closed joeldenning closed 2 years ago
Here are the lines to change - should check whether it's react 18 or not when determining the default:
You think a version check is what you want, or do you want to do an existence check?
if(opts.ReactDOM.createRoot) {
... new stuff
} else {
... old stuff
}
It appears that createRoot
isn't defined on ReactDOM in v17, so I think it would be safe?
Yeah probably just checking whether createRoot exists is enough. Experimental builds of react 16 and 17 had it, but those using the experimental builds probably would want to use createRoot since that was the whole purpose of using those builds.
Updated React 18 createRoot information here: https://github.com/reactwg/react-18/discussions/5
It seems that ReactDOM: typeof ReactDOM;
(which is not correct for React v18+ users) should be updated from SingleSpaReactOpts
, since React v18 has already be supported in the latest version, otherwise, it will raise a TypeScript incompatible error with following message:
TS2740: Type 'typeof import("\*\*/node_modules/@types/react-dom/client")' is missing the following properties from type 'typeof import("\*\*/node_modules/@types/react-dom/index")': findDOMNode, unmountComponentAtNode, createPortal, flushSync, and 5 more.
single-spa-react.d.ts(9, 3): The expected type comes from property 'ReactDOM' which is declared here on type 'SingleSpaReactOpts<AppProps>'
Published in v5.0.0
@filoxo In docs it still declared as render
is the default renderType. I thought this PR referred in this issue changed the default renderType to createRoot
🤔
Published in v5.0.0
Link https://github.com/single-spa/single-spa-react/releases/tag/v5.0.0
What's Changed React 18 support. by @filoxo in https://github.com/single-spa/single-spa-react/pull/148
if upgrading from single-spa-react@4, replace ReactDOM with ReactDOMClient Change default renderType to createRoot. by @filoxo in https://github.com/single-spa/single-spa-react/pull/148
if your application is using React 17 and below, you must explicitly define the renderType option. For most, this is "render" but others are also supported.
React 18 console warns when you run ReactDOM.render() rather than ReactDOM.createRoot().render(). I think single-spa-react should do a React version check and start defaulting to createRoot if it's at least react 18.