Skip to content

Commit a506ed6

Browse files
giaBaoJSmeta-codesync[bot]
authored andcommitted
Expose ReactNativeFeatureFlags through react-private-interface (#57940)
Summary: Fixes #57933. `react-native/virtualized-lists` is published separately and imported `ReactNativeFeatureFlags` through `react-native/src/private/featureflags/ReactNativeFeatureFlags`, which is not listed in `react-native`'s `"exports"`. Metro therefore warned and fell back to file-based resolution whenever an app rendered a virtualized list. Thanks huntie for the patch and the direction — this PR now applies it instead of the original approach: - `ReactNativeFeatureFlags` is exposed on the existing private package boundary, `react-native/react-private-interface` (both the runtime getter and the `.js.flow` re-export); - `VirtualizedList.js` and `VirtualizeUtils.js` import it from there. No new `src/private/*` subpath is exported, and the feature-flag singleton is unchanged. Per your review, the `scripts/monorepo-tests/__tests__/check-packages-test.js` and `scripts/shared/monorepoUtils.js` changes have been dropped — the PR is now just the patch above. Happy to look at enabling `react-native/no-deep-imports` on `virtualized-lists` as a follow-up if that's wanted. `VirtualizeUtils.js` is included alongside `VirtualizedList.js` because it carried the same runtime deep import. The remaining occurrences are out of scope: the four in `react-native/jest-preset` are all `import type` and are erased before resolution, and the one in `VirtualizeUtils-test.js` is not shipped (`virtualized-lists` excludes `**/__tests__/**` from `files`). ## Changelog: [GENERAL] [FIXED] - Fix the Metro package-exports warning caused by `react-native/virtualized-lists` importing an unexported React Native subpath. Pull Request resolved: #57940 Test Plan: No new test is added. The existing `virtualized-lists` suites already cover this route, because `VirtualizeUtils`/`VirtualizedList` read the flags at runtime through the new boundary. Counterfactual — dropping only the `ReactNativeFeatureFlags` getter and its `import typeof` from `react-private-interface.js`, keeping the two `virtualized-lists` imports: ```text TypeError: Cannot read properties of undefined (reading 'fixVirtualizeListCollapseWindowSize') 182 | let lastWillAddMore; 183 | > 184 | if (ReactNativeFeatureFlags.fixVirtualizeListCollapseWindowSize()) { | ^ at computeWindowedRenderLimits (packages/virtualized-lists/Lists/VirtualizeUtils.js:184:32) at Object.<anonymous> (packages/virtualized-lists/Lists/__tests__/VirtualizeUtils-test.js:261:47) Test Suites: 2 failed, 6 passed, 8 total Tests: 20 failed, 1 skipped, 151 passed, 172 total ``` Restoring the getter makes it green again. ```text $ yarn jest packages/virtualized-lists scripts/monorepo-tests packages/react-native/Libraries/ReactPrivate --runInBand Test Suites: 9 passed, 9 total Tests: 1 skipped, 176 passed, 177 total Snapshots: 69 passed, 69 total $ yarn flow-check Found 0 errors $ yarn lint $ eslint --max-warnings 0 . Done in 10.23s. ``` Reviewed By: javache Differential Revision: D119164284 Pulled By: cortinico fbshipit-source-id: 1e8ae3b85ae7fb28c55f207f887a97aad85b563c
1 parent 156a9a2 commit a506ed6

4 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/react-native/src/react-private-interface.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type {DangerouslyImpreciseStyleProp} from '../Libraries/StyleSheet/StyleS
4848
import typeof deepFreezeAndThrowOnMutationInDev from '../Libraries/Utilities/deepFreezeAndThrowOnMutationInDev';
4949
import typeof deepDiffer from '../Libraries/Utilities/differ/deepDiffer';
5050
import typeof Platform from '../Libraries/Utilities/Platform';
51+
import typeof * as ReactNativeFeatureFlags from './private/featureflags/ReactNativeFeatureFlags';
5152
import typeof dispatchNativeEvent from './private/renderer/events/dispatchNativeEvent';
5253
import typeof CustomEvent from './private/webapis/dom/events/CustomEvent';
5354

@@ -69,6 +70,9 @@ module.exports = {
6970
get RCTEventEmitter(): RCTEventEmitter {
7071
return require('../Libraries/EventEmitter/RCTEventEmitter').default;
7172
},
73+
get ReactNativeFeatureFlags(): ReactNativeFeatureFlags {
74+
return require('./private/featureflags/ReactNativeFeatureFlags');
75+
},
7276
get ReactNativeViewConfigRegistry(): ReactNativeViewConfigRegistry {
7377
return require('../Libraries/Renderer/shims/ReactNativeViewConfigRegistry');
7478
},

packages/react-native/src/react-private-interface.js.flow

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {default as BatchedBridge} from '../Libraries/BatchedBridge/BatchedBridge
2323
export {default as ExceptionsManager} from '../Libraries/Core/ExceptionsManager';
2424
export {default as Platform} from '../Libraries/Utilities/Platform';
2525
export {default as RCTEventEmitter} from '../Libraries/EventEmitter/RCTEventEmitter';
26+
export * as ReactNativeFeatureFlags from './private/featureflags/ReactNativeFeatureFlags';
2627
export * as ReactNativeViewConfigRegistry from '../Libraries/Renderer/shims/ReactNativeViewConfigRegistry';
2728
export {default as TextInputState} from '../Libraries/Components/TextInput/TextInputState';
2829
export {default as UIManager} from '../Libraries/ReactNative/UIManager';

packages/virtualized-lists/Lists/VirtualizeUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import type ListMetricsAggregator from './ListMetricsAggregator';
1414
import type {CellMetricProps} from './ListMetricsAggregator';
1515

16-
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';
16+
import {ReactNativeFeatureFlags} from 'react-native/react-private-interface';
1717

1818
/**
1919
* Used to find the indices of the frames that overlap the given offsets. Useful for finding the

packages/virtualized-lists/Lists/VirtualizedList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import {
6464
View,
6565
findNodeHandle,
6666
} from 'react-native';
67-
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';
67+
import {ReactNativeFeatureFlags} from 'react-native/react-private-interface';
6868

6969
export type {ListRenderItemInfo, ListRenderItem, Separators};
7070

0 commit comments

Comments
 (0)