Skip to content

Commit e5c5935

Browse files
authored
Prevent bundling of Node polyfills when importing TestUtils/TestRenderer (#15305)
1 parent 7318723 commit e5c5935

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/shared/enqueueTask.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import warningWithoutStack from './warningWithoutStack';
1212
let didWarnAboutMessageChannel = false;
1313
let enqueueTask;
1414
try {
15+
// read require off the module object to get around the bundlers.
16+
// we don't want them to detect a require and bundle a Node polyfill.
17+
let requireString = ('require' + Math.random()).slice(0, 7);
18+
let nodeRequire = module && module[requireString];
1519
// assuming we're in node, let's try to get node's
16-
// version of setImmediate, bypassing fake timers if any
17-
let r = require; // trick packagers not to bundle this stuff.
18-
enqueueTask = r('timers').setImmediate;
20+
// version of setImmediate, bypassing fake timers if any.
21+
enqueueTask = nodeRequire('timers').setImmediate;
1922
} catch (_err) {
2023
// we're in a browser
2124
// we can't use regular timers because they may still be faked

0 commit comments

Comments
 (0)