Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a1c817

Browse files
Sebastian Silbermanneps1lon
Sebastian Silbermann
authored andcommitted
Fix overlapping act call when using cleanup
1 parent 5e3f42a commit 1a1c817

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

‎src/__tests__/cleanup.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ test('cleanup runs effect cleanup functions', async () => {
4141
expect(spy).toHaveBeenCalledTimes(1)
4242
})
4343

44+
test('cleanup cleans up every root and disconnects containers', async () => {
45+
const {container: container1} = await render(<div />)
46+
const {container: container2} = await render(<span />)
47+
48+
await cleanup()
49+
50+
expect(container1).toBeEmptyDOMElement()
51+
expect(container1.isConnected).toBe(false)
52+
expect(container2).toBeEmptyDOMElement()
53+
expect(container2.isConnected).toBe(false)
54+
})
55+
4456
describe('fake timers and missing act warnings', () => {
4557
beforeEach(() => {
4658
jest.resetAllMocks()

‎src/pure.js‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,14 @@ async function render(
239239
}
240240

241241
async function cleanup() {
242-
await Promise.all(
243-
mountedRootEntries.map(async ({root, container}) => {
244-
await act(() => {
245-
root.unmount()
246-
})
247-
if (container.parentNode === document.body) {
248-
document.body.removeChild(container)
249-
}
250-
}),
251-
)
242+
for (const {container, root} of mountedRootEntries) {
243+
// eslint-disable-next-line no-await-in-loop -- Overlapping act calls are not allowed.
244+
await root.unmount()
245+
if (container.parentNode === document.body) {
246+
document.body.removeChild(container)
247+
}
248+
}
249+
252250
mountedRootEntries.length = 0
253251
mountedContainers.clear()
254252
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /