Skip to content

Commit 82ff129

Browse files
committed
Fix false positive warning about MessageChannel
1 parent 6cb2832 commit 82ff129

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/flush-microtasks.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ try {
2222
// we can't use regular timers because they may still be faked
2323
// so we try MessageChannel+postMessage instead
2424
enqueueTask = (callback) => {
25-
if (didWarnAboutMessageChannel === false) {
25+
const supportsMessageChannel = typeof MessageChannel === 'function'
26+
if (supportsMessageChannel) {
27+
const channel = new MessageChannel()
28+
channel.port1.onmessage = callback
29+
channel.port2.postMessage(undefined)
30+
} else if (didWarnAboutMessageChannel === false) {
2631
didWarnAboutMessageChannel = true
32+
2733
// eslint-disable-next-line no-console
2834
console.error(
29-
typeof MessageChannel !== 'undefined',
3035
'This browser does not have a MessageChannel implementation, ' +
3136
'so enqueuing tasks via await act(async () => ...) will fail. ' +
3237
'Please file an issue at https://github.com/facebook/react/issues ' +
3338
'if you encounter this warning.'
3439
)
3540
}
36-
const channel = new MessageChannel()
37-
channel.port1.onmessage = callback
38-
channel.port2.postMessage(undefined)
3941
}
4042
}
4143

0 commit comments

Comments
 (0)