Skip to content

Commit 563b934

Browse files
committed
early bailout in cleanup
1 parent 084b691 commit 563b934

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/renderWithoutAct.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ This is not supported. Please use \`disableActEnvironment\` to disable the act e
209209
}
210210

211211
export function cleanup() {
212+
if (!mountedRootEntries.length) {
213+
// nothing to clean up
214+
return
215+
}
216+
212217
// there is a good chance this happens outside of a test, where the user
213218
// has no control over enabling or disabling the React Act environment,
214219
// so we do it for them here.
@@ -218,13 +223,13 @@ export function cleanup() {
218223
adjustTestingLibConfig: false,
219224
} satisfies /* ensure that all possible options are passed here in case we add more in the future */ Required<DisableActEnvironmentOptions>)
220225
try {
221-
mountedRootEntries.forEach(({root, container}) => {
226+
for (const {root, container} of mountedRootEntries) {
222227
root.unmount()
223228

224229
if (container.parentNode === document.body) {
225230
document.body.removeChild(container)
226231
}
227-
})
232+
}
228233
mountedRootEntries.length = 0
229234
mountedContainers.clear()
230235
} finally {

0 commit comments

Comments
 (0)