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

Change default renderType based on React version. Resolves #202 #203

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-bats-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"single-spa-react": patch
---

Automatically support React 17 with default opts. Resolves #202
10 changes: 9 additions & 1 deletion src/single-spa-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const defaultOpts = {
loadRootComponent: null,

// optional opts
renderType: "createRoot",
errorBoundary: null,
errorBoundaryClass: null,
domElementGetter: null,
Expand Down Expand Up @@ -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`
Expand Down