Skip to content

Commit 14b0670

Browse files
committed
refactor: use same function for wrapping UI if needed
1 parent 49cbee6 commit 14b0670

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/pure.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ const mountedContainers = new Set()
7777
*/
7878
const mountedRootEntries = []
7979

80+
function wrapUiIfNeeded(innerElement, wrapperComponent) {
81+
return wrapperComponent
82+
? React.createElement(wrapperComponent, null, innerElement)
83+
: innerElement
84+
}
85+
8086
function createConcurrentRoot(
8187
container,
8288
{hydrate, ui, wrapper: WrapperComponent},
@@ -86,7 +92,7 @@ function createConcurrentRoot(
8692
act(() => {
8793
root = ReactDOMClient.hydrateRoot(
8894
container,
89-
WrapperComponent ? React.createElement(WrapperComponent, null, ui) : ui,
95+
wrapUiIfNeeded(ui, WrapperComponent),
9096
)
9197
})
9298
} else {
@@ -130,16 +136,11 @@ function renderRoot(
130136
ui,
131137
{baseElement, container, hydrate, queries, root, wrapper: WrapperComponent},
132138
) {
133-
const wrapUiIfNeeded = innerElement =>
134-
WrapperComponent
135-
? React.createElement(WrapperComponent, null, innerElement)
136-
: innerElement
137-
138139
act(() => {
139140
if (hydrate) {
140-
root.hydrate(wrapUiIfNeeded(ui), container)
141+
root.hydrate(wrapUiIfNeeded(ui, WrapperComponent), container)
141142
} else {
142-
root.render(wrapUiIfNeeded(ui), container)
143+
root.render(wrapUiIfNeeded(ui, WrapperComponent), container)
143144
}
144145
})
145146

0 commit comments

Comments
 (0)