Skip to content

Commit 1137854

Browse files
committed
Import dynamic RN flags from external module
Internal feature flags that we wish to control with a GK can now be imported from an external module, which I've called "ReactNativeInternalFeatureFlags". We'll need to add this module to the downstream repo. We can't yet use this in our tests, because we don't have a test configuration that runs against the React Native feature flags fork. We should set up that up the same way we did for www.
1 parent 2fb2dbb commit 1137854

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
*/
9+
10+
import typeof * as ExportsType from './ReactFeatureFlags.native-fb-dynamic';
11+
import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
12+
13+
// In xplat, these flags are controlled by GKs. Because most GKs have some
14+
// population running in either mode, we should run our tests that way, too,
15+
//
16+
// Use __VARIANT__ to simulate a GK. The tests will be run twice: once
17+
// with the __VARIANT__ set to `true`, and once set to `false`.
18+
//
19+
// TODO: __VARIANT__ isn't supported for React Native flags yet. You can set the
20+
// flag here but it won't be set to `true` in any of our test runs. Need to
21+
// update the test configuration.
22+
23+
export const enablePersistentOffscreenHostContainer = __VARIANT__;
24+
25+
// Flow magic to verify the exports of this file match the original version.
26+
// eslint-disable-next-line no-unused-vars
27+
type Check<_X, Y: _X, X: Y = _X> = null;
28+
// eslint-disable-next-line no-unused-expressions
29+
(null: Check<ExportsType, DynamicFlagsType>);

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
1111
import typeof * as ExportsType from './ReactFeatureFlags.native-fb';
1212

13+
// Re-export dynamic flags from the internal module. Intentionally using *
14+
// because this import is compiled to a `require` call.
15+
import * as dynamicFlags from 'ReactNativeInternalFeatureFlags';
16+
17+
// We destructure each value before re-exporting to avoid a dynamic look-up on
18+
// the exports object every time a flag is read.
19+
export const {enablePersistentOffscreenHostContainer} = dynamicFlags;
20+
1321
// The rest of the flags are static for better dead code elimination.
1422
export const enableDebugTracing = false;
1523
export const enableSchedulingProfiler = false;
@@ -60,8 +68,6 @@ export const disableSchedulerTimeoutInWorkLoop = false;
6068
export const enableLazyContextPropagation = false;
6169
export const enableSyncDefaultUpdates = true;
6270
export const allowConcurrentByDefault = true;
63-
// TODO: Import this from internal ReactNativeFeatureFlags instead
64-
export const enablePersistentOffscreenHostContainer = __EXPERIMENTAL__;
6571

6672
// Flow magic to verify the exports of this file match the original version.
6773
// eslint-disable-next-line no-unused-vars

scripts/flow/config/flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
./scripts/flow/react-devtools.js
3535
./scripts/flow/react-native-host-hooks.js
3636
./scripts/flow/react-relay-hooks.js
37+
./scripts/flow/xplat.js
3738

3839
[lints]
3940
untyped-type-import=error

scripts/flow/xplat.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
declare module 'ReactNativeInternalFeatureFlags' {
11+
declare export var enablePersistentOffscreenHostContainer: boolean;
12+
}

scripts/rollup/bundles.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const bundles = [
7979
moduleType: ISOMORPHIC,
8080
entry: 'react',
8181
global: 'React',
82-
externals: [],
82+
externals: ['ReactNativeInternalFeatureFlags'],
8383
},
8484

8585
/******* Isomorphic Shared Subset *******/
@@ -105,7 +105,7 @@ const bundles = [
105105
moduleType: ISOMORPHIC,
106106
entry: 'react/jsx-runtime',
107107
global: 'JSXRuntime',
108-
externals: ['react'],
108+
externals: ['react', 'ReactNativeInternalFeatureFlags'],
109109
},
110110

111111
/******* React JSX DEV Runtime *******/
@@ -124,7 +124,7 @@ const bundles = [
124124
moduleType: ISOMORPHIC,
125125
entry: 'react/jsx-dev-runtime',
126126
global: 'JSXDEVRuntime',
127-
externals: ['react'],
127+
externals: ['react', 'ReactNativeInternalFeatureFlags'],
128128
},
129129

130130
/******* React Fetch Browser (experimental, new) *******/
@@ -372,6 +372,7 @@ const bundles = [
372372
'react',
373373
'ReactFlightNativeRelayServerIntegration',
374374
'JSResourceReferenceImpl',
375+
'ReactNativeInternalFeatureFlags',
375376
],
376377
},
377378

@@ -385,6 +386,7 @@ const bundles = [
385386
'react',
386387
'ReactFlightNativeRelayClientIntegration',
387388
'JSResourceReferenceImpl',
389+
'ReactNativeInternalFeatureFlags',
388390
],
389391
},
390392

@@ -432,7 +434,7 @@ const bundles = [
432434
moduleType: RENDERER,
433435
entry: 'react-native-renderer',
434436
global: 'ReactNativeRenderer',
435-
externals: ['react-native'],
437+
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
436438
babel: opts =>
437439
Object.assign({}, opts, {
438440
plugins: opts.plugins.concat([
@@ -462,7 +464,7 @@ const bundles = [
462464
moduleType: RENDERER,
463465
entry: 'react-native-renderer/fabric',
464466
global: 'ReactFabric',
465-
externals: ['react-native'],
467+
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
466468
babel: opts =>
467469
Object.assign({}, opts, {
468470
plugins: opts.plugins.concat([
@@ -499,7 +501,12 @@ const bundles = [
499501
moduleType: RENDERER,
500502
entry: 'react-test-renderer',
501503
global: 'ReactTestRenderer',
502-
externals: ['react', 'scheduler', 'scheduler/unstable_mock'],
504+
externals: [
505+
'react',
506+
'scheduler',
507+
'scheduler/unstable_mock',
508+
'ReactNativeInternalFeatureFlags',
509+
],
503510
babel: opts =>
504511
Object.assign({}, opts, {
505512
plugins: opts.plugins.concat([
@@ -692,7 +699,7 @@ const bundles = [
692699
moduleType: ISOMORPHIC,
693700
entry: 'scheduler',
694701
global: 'Scheduler',
695-
externals: [],
702+
externals: ['ReactNativeInternalFeatureFlags'],
696703
},
697704

698705
/******* React Scheduler Mock (experimental) *******/
@@ -710,7 +717,7 @@ const bundles = [
710717
moduleType: ISOMORPHIC,
711718
entry: 'scheduler/unstable_mock',
712719
global: 'SchedulerMock',
713-
externals: [],
720+
externals: ['ReactNativeInternalFeatureFlags'],
714721
},
715722

716723
/******* React Scheduler Post Task (experimental) *******/

scripts/rollup/modules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const importSideEffects = Object.freeze({
2121
'react-fetch/node': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
2222
'react-dom': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
2323
url: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
24+
ReactNativeInternalFeatureFlags: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
2425
});
2526

2627
// Bundles exporting globals that other modules rely on.
@@ -31,6 +32,7 @@ const knownGlobals = Object.freeze({
3132
'react-interactions/events/tap': 'ReactEventsTap',
3233
scheduler: 'Scheduler',
3334
'scheduler/unstable_mock': 'SchedulerMock',
35+
ReactNativeInternalFeatureFlags: 'ReactNativeInternalFeatureFlags',
3436
});
3537

3638
// Given ['react'] in bundle externals, returns { 'react': 'React' }.

0 commit comments

Comments
 (0)