Skip to content

fix: False positive warning about MessageChannel #522

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

Merged
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