From 97ee02902643b447673764f17bda0351401d8e40 Mon Sep 17 00:00:00 2001 From: joeldenning Date: Thu, 4 Jan 2024 16:56:35 -0700 Subject: [PATCH 1/2] Change default renderType based on React version. Resolves #202 --- .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..f2bd8a6 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.ReactDOM?.createRoot || 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` From c7928a6de8d9b96bab8e723c40958cfaa2e80e74 Mon Sep 17 00:00:00 2001 From: joeldenning Date: Thu, 4 Jan 2024 17:49:47 -0700 Subject: [PATCH 2/2] Milan's feedback --- src/single-spa-react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/single-spa-react.js b/src/single-spa-react.js index f2bd8a6..c999e82 100644 --- a/src/single-spa-react.js +++ b/src/single-spa-react.js @@ -69,7 +69,7 @@ function singleSpaReact(userOpts) { if (!opts.renderType) { // https://github.com/single-spa/single-spa-react/issues/202 - if (opts.ReactDOM?.createRoot || opts.ReactDOMClient?.createRoot) { + if (opts.ReactDOMClient?.createRoot) { opts.renderType = "createRoot"; } else { opts.renderType = "render";