From ec968f2bb3658b783a4ba60519a73ab71962966f Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Thu, 4 Jan 2024 18:12:21 -0700 Subject: [PATCH] Change default renderType based on React version. Resolves #202 (#203) --- .changeset/fifty-bats-stare.md | 5 +++++ src/single-spa-react.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/fifty-bats-stare.md diff --git a/.changeset/fifty-bats-stare.md b/.changeset/fifty-bats-stare.md new file mode 100644 index 0000000..25edd77 --- /dev/null +++ b/.changeset/fifty-bats-stare.md @@ -0,0 +1,5 @@ +--- +"single-spa-react": patch +--- + +Automatically support React 17 with default opts. Resolves #202 diff --git a/src/single-spa-react.js b/src/single-spa-react.js index 64a5cd8..c999e82 100644 --- a/src/single-spa-react.js +++ b/src/single-spa-react.js @@ -36,7 +36,6 @@ const defaultOpts = { loadRootComponent: null, // optional opts - renderType: "createRoot", errorBoundary: null, errorBoundaryClass: null, domElementGetter: null, @@ -68,6 +67,15 @@ function singleSpaReact(userOpts) { ); } + if (!opts.renderType) { + // https://github.com/single-spa/single-spa-react/issues/202 + if (opts.ReactDOMClient?.createRoot) { + opts.renderType = "createRoot"; + } else { + opts.renderType = "render"; + } + } + if (!opts.rootComponent && !opts.loadRootComponent) { throw new Error( `single-spa-react must be passed opts.rootComponent or opts.loadRootComponent`