Skip to content
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
14 changes: 14 additions & 0 deletions src/__tests__/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ test('cleanup does not error when an element is not a child', async () => {
render(<div />, {container: document.createElement('div')})
await cleanup()
})

test('cleanup waits for queued microtasks during unmount sequence', async () => {
const spy = jest.fn()

const Test = () => {
React.useEffect(() => () => setImmediate(spy))

return null
}

render(<Test />)
await cleanup()
expect(spy).toHaveBeenCalledTimes(1)
})
4 changes: 3 additions & 1 deletion src/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ function render(
}

async function cleanup() {
await flush()
mountedContainers.forEach(cleanupAtContainer)
// flush microtask queue after unmounting in case
// unmount sequence generates new microtasks
await flush()
}

// maybe one day we'll expose this (perhaps even as a utility returned by render).
Expand Down