single-spa / single-spa-react

Single-spa lifecycles helper for React applications
https://single-spa.js.org/docs/ecosystem-react.html
MIT License
227 stars 63 forks source link

Change default renderType to createRoot in React 18 #115

Closed joeldenning closed 2 years ago

joeldenning commented 3 years ago

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.

joeldenning commented 3 years ago

Here are the lines to change - should check whether it's react 18 or not when determining the default:

https://github.com/single-spa/single-spa-react/blob/025245b5b00b56991c38a70dd2ab189f7134b8d0/src/single-spa-react.js#L269-L270

frehner commented 3 years ago

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?

joeldenning commented 3 years ago

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.

filoxo commented 2 years ago

Updated React 18 createRoot information here: https://github.com/reactwg/react-18/discussions/5

hijiangtao commented 2 years ago

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>'
filoxo commented 2 years ago

Published in v5.0.0

serpilacar commented 1 year ago

@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 🤔

italoservio commented 1 year ago

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