Skip to content
Merged
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
12 changes: 7 additions & 5 deletions src/flush-microtasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ try {
// we can't use regular timers because they may still be faked
// so we try MessageChannel+postMessage instead
enqueueTask = callback => {
if (didWarnAboutMessageChannel === false) {
const supportsMessageChannel = typeof MessageChannel === 'function'
if (supportsMessageChannel) {
const channel = new MessageChannel()
channel.port1.onmessage = callback
channel.port2.postMessage(undefined)
} else if (didWarnAboutMessageChannel === false) {
didWarnAboutMessageChannel = true

// eslint-disable-next-line no-console
console.error(
typeof MessageChannel !== 'undefined',
'This browser does not have a MessageChannel implementation, ' +
'so enqueuing tasks via await act(async () => ...) will fail. ' +
'Please file an issue at https://github.com/facebook/react/issues ' +
'if you encounter this warning.',
)
}
const channel = new MessageChannel()
channel.port1.onmessage = callback
channel.port2.postMessage(undefined)
}
}

Expand Down