Skip to content

Commit 0d04bff

Browse files
committed
fix(render): Actually hydrate with given ui
1 parent 8cf1357 commit 0d04bff

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/pure.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,36 @@ const mountedContainers = new Set()
6060
*/
6161
const mountedRootEntries = []
6262

63-
function createConcurrentRoot(container, options) {
63+
function createConcurrentRoot(
64+
container,
65+
{hydrate, ui, wrapper: WrapperComponent},
66+
) {
6467
if (typeof ReactDOM.createRoot !== 'function') {
6568
throw new TypeError(
6669
`Attempted to use concurrent React with \`react-dom@${ReactDOM.version}\`. Be sure to use the \`next\` or \`experimental\` release channel (https://reactjs.org/docs/release-channels.html).'`,
6770
)
6871
}
69-
const root = options.hydrate
70-
? ReactDOM.hydrateRoot(container)
71-
: ReactDOM.createRoot(container)
72+
let root
73+
if (hydrate) {
74+
act(() => {
75+
root = ReactDOM.hydrateRoot(
76+
container,
77+
WrapperComponent ? React.createElement(WrapperComponent, null, ui) : ui,
78+
)
79+
})
80+
} else {
81+
root = ReactDOM.createRoot(container)
82+
}
7283

7384
return {
74-
hydrate(element) {
85+
hydrate() {
7586
/* istanbul ignore if */
76-
if (!options.hydrate) {
87+
if (!hydrate) {
7788
throw new Error(
7889
'Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.',
7990
)
8091
}
81-
root.render(element)
92+
// Nothing to do since hydration happens when creating the root object.
8293
},
8394
render(element) {
8495
root.render(element)
@@ -183,7 +194,7 @@ function render(
183194
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first.
184195
if (!mountedContainers.has(container)) {
185196
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot
186-
root = createRootImpl(container, {hydrate})
197+
root = createRootImpl(container, {hydrate, ui, wrapper})
187198

188199
mountedRootEntries.push({container, root})
189200
// we'll add it to the mounted containers regardless of whether it's actually

0 commit comments

Comments
 (0)