Skip to content

Commit

Permalink
Prevent bundling of Node polyfills when importing TestUtils/TestRende…
Browse files Browse the repository at this point in the history
…rer (#15305)
  • Loading branch information
gaearon committed Apr 3, 2019
1 parent 7318723 commit e5c5935
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/shared/enqueueTask.js
Expand Up @@ -12,10 +12,13 @@ import warningWithoutStack from './warningWithoutStack';
let didWarnAboutMessageChannel = false;
let enqueueTask;
try {
// read require off the module object to get around the bundlers.
// we don't want them to detect a require and bundle a Node polyfill.
let requireString = ('require' + Math.random()).slice(0, 7);
let nodeRequire = module && module[requireString];
// assuming we're in node, let's try to get node's
// version of setImmediate, bypassing fake timers if any
let r = require; // trick packagers not to bundle this stuff.
enqueueTask = r('timers').setImmediate;
// version of setImmediate, bypassing fake timers if any.
enqueueTask = nodeRequire('timers').setImmediate;
} catch (_err) {
// we're in a browser
// we can't use regular timers because they may still be faked
Expand Down

0 comments on commit e5c5935

Please sign in to comment.