Skip to content

Commit 11460a3

Browse files
eps1lonKent C. Dodds
authored and
Kent C. Dodds
committed
fix: False positive warning about MessageChannel (#522)
1 parent 2cac7b9 commit 11460a3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/flush-microtasks.js

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

0 commit comments

Comments
 (0)