mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
* Fix dead code elimination for feature flags
Turning flags into named exports fixes dead code elimination.
This required some restructuring of how we verify that flag types match up. I used the Check<> trick combined with import typeof, as suggested by @calebmer.
For www, we can no longer re-export `require('ReactFeatureFlags')` directly, and instead destructure it. This means flags have to be known at init time. This is already the case so it's not a problem. In fact it may be better since it removes extra property access in tight paths.
For things that we *want* to be dynamic on www (currently, only performance flag) we can export a function to toggle it, and then put it on the secret exports. In fact this is better than just letting everyone mutate the flag at arbitrary times since we can provide, e.g., a ref counting interface to it.
* Record sizes
13 lines
470 B
JavaScript
13 lines
470 B
JavaScript
'use strict';
|
|
|
|
jest.mock('shared/ReactFeatureFlags', () => {
|
|
// We can alter flags based on environment here
|
|
// (e.g. for CI runs with different flags).
|
|
return require.requireActual('shared/ReactFeatureFlags');
|
|
});
|
|
|
|
// Error logging varies between Fiber and Stack;
|
|
// Rather than fork dozens of tests, mock the error-logging file by default.
|
|
// TODO: direct imports like some-package/src/* are bad. Fix me.
|
|
jest.mock('react-reconciler/src/ReactFiberErrorLogger');
|