mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
While most builds of Flight and Fizz schedule work in new tasks some do execute work synchronously. While this is necessary for legacy APIs like renderToString for modern APIs there really isn't a great reason to do this synchronously. We could schedule works as microtasks but we actually want to yield so the runtime can run events and other things that will unblock additional work before starting the next work loop. This change updates all non-legacy uses to be async using the best availalble macrotask scheduler. Browser now uses postMessage Bun uses setTimeout because while it also supports setImmediate the scheduling is not as eager as the same API in node the FB build also uses setTimeout This change required a number of changes to tests which were utilizing the sync nature of work in the Browser builds to avoid having to manage timers and tasks. I added a patch to install MessageChannel which is required by the browser builds and made this patched version integrate with the Scheduler mock. This way we can effectively use `act` to flush flight and fizz work similar to how we do this on the client.
28 lines
884 B
JavaScript
28 lines
884 B
JavaScript
/* eslint-disable */
|
|
|
|
const NODE_ENV = process.env.NODE_ENV;
|
|
if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
|
|
throw new Error('NODE_ENV must either be set to development or production.');
|
|
}
|
|
global.__DEV__ = NODE_ENV === 'development';
|
|
global.__EXTENSION__ = false;
|
|
global.__TEST__ = NODE_ENV === 'test';
|
|
global.__PROFILE__ = NODE_ENV === 'development';
|
|
|
|
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL;
|
|
|
|
// Default to running tests in experimental mode. If the release channel is
|
|
// set via an environment variable, then check if it's "experimental".
|
|
global.__EXPERIMENTAL__ =
|
|
typeof RELEASE_CHANNEL === 'string'
|
|
? RELEASE_CHANNEL === 'experimental'
|
|
: true;
|
|
|
|
global.__VARIANT__ = !!process.env.VARIANT;
|
|
|
|
if (typeof window !== 'undefined') {
|
|
} else {
|
|
global.AbortController =
|
|
require('abortcontroller-polyfill/dist/cjs-ponyfill').AbortController;
|
|
}
|