single-spa / single-spa-react

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

Do loadRootComponent-props have to be optional? #211

Closed JohannesConrad closed 2 weeks ago

JohannesConrad commented 3 months ago

Hi, I am working with single-spa-react in a project and recently updated from version 4.x to 6.0.1. With the Commit for React18 support there was a typing for loadRootComponent introduced that causes issues. The props?: RootComponentProps are now optional which makes a defined check necessary in some instances. https://github.com/single-spa/single-spa-react/blob/6c80e56d5084002e38ae215f41f796608dc49725/types/single-spa-react.d.ts#L29

Digging into the code I found: https://github.com/single-spa/single-spa-react/blob/6c80e56d5084002e38ae215f41f796608dc49725/src/single-spa-react.js#L52 If I interpret that correctly it will fail if the props from above are undefined anyway.

I am not sure if there is something I missed and it's necessary for the props to be optional.

I expected the prop to look like:

loadRootComponent?: (
    props: RootComponentProps
) => Promise<React.ElementType<RootComponentProps>>;

Thanks in advance for any feedback and have a lovely day Johannes 🐕

joeldenning commented 2 weeks ago

The two lines of you code that were linked are unrelated. The line that throws an error is related to the singleSpaReact function, not the loadRootComponent function