Skip to content
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

Support React 18 identifierPrefix with createRoot/hydrateRoot #152

Open
JamiesWhiteShirt opened this issue Sep 14, 2022 · 3 comments
Open
Assignees

Comments

@JamiesWhiteShirt
Copy link

ReactDOM has the identifierPrefix option for createRoot/hydrateRoot which should be used when multiple roots are used on the same page to support the new useId hook. Having multiple roots happens to be particularly likely when using single-spa, so identifierPrefix should be supported and recommended to use with single-spa-react.

@filoxo
Copy link
Contributor

filoxo commented Sep 14, 2022

Good to know! I hadn't come across this at all when implementing React 18 support. I can look into this.

@filoxo filoxo self-assigned this Sep 16, 2022
@WViiras
Copy link

WViiras commented Oct 27, 2022

this seems like a workaround to the problem

const lifecycles = singleSpaReact({
  errorBoundary(err, info, props) {
    return null;
  },
  React,
  ReactDOMClient: {
    ...ReactDOMClient,
    createRoot: (container: Element | DocumentFragment, options?: RootOptions) => {
      return ReactDOMClient.createRoot(container, {
        ...options,
        identifierPrefix: "id-prefix",
      });
    },
  },
  renderType: "createRoot",
  rootComponent: Root,
});

@lucasfreyptml
Copy link

lucasfreyptml commented Jun 19, 2023

How do you make this work with TS ? I am getting this with your method :

Argument of type '{ errorBoundary(err: Error, info: ErrorInfo, props: AppProps): any; React: typeof React; ReactDOMClient: any; renderType: "createRoot"; rootComponent: () => Element; }' is not assignable to parameter of type 'SingleSpaReactOpts<AppProps>'.
  Object literal may only specify known properties, and 'ReactDOMClient' does not exist in type 'SingleSpaReactOpts<AppProps>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants