Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cleanup): Cleanup should flush microtask queue after unmounting containers #632

Merged
merged 2 commits into from Jun 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/cleanup.js
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
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