Skip to content

Commit 6dce0c1

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Remove enableBridgelessArchitecture flag and global.RN$Bridgeless checks - RFC (#57055)
Summary: Pull Request resolved: #57055 Changelog: [General][Breaking] Remove enableBridgelessArchitecture flag and global.RN$Bridgeless checks Differential Revision: D107314734
1 parent f85b15b commit 6dce0c1

65 files changed

Lines changed: 219 additions & 792 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react-native/Libraries/Animated/shouldUseTurboAnimatedModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function shouldUseTurboAnimatedModule(): boolean {
1515
if (ReactNativeFeatureFlags.cxxNativeAnimatedEnabled()) {
1616
return false;
1717
} else {
18-
return Platform.OS === 'ios' && global.RN$Bridgeless === true;
18+
return Platform.OS === 'ios';
1919
}
2020
}
2121

packages/react-native/Libraries/BatchedBridge/MessageQueue.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,9 @@ class MessageQueue {
417417
const n = callableModuleNames.length;
418418
const callableModuleNameList = callableModuleNames.join(', ');
419419

420-
// TODO(T122225939): Remove after investigation: Why are we getting to this line in bridgeless mode?
421-
const isBridgelessMode =
422-
global.RN$Bridgeless === true ? 'true' : 'false';
423420
invariant(
424421
false,
425-
`Failed to call into JavaScript module method ${module}.${method}(). Module has not been registered as callable. Bridgeless Mode: ${isBridgelessMode}. Registered callable JavaScript modules (n = ${n}): ${callableModuleNameList}.
422+
`Failed to call into JavaScript module method ${module}.${method}(). Module has not been registered as callable. Registered callable JavaScript modules (n = ${n}): ${callableModuleNameList}.
426423
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.`,
427424
);
428425
}

packages/react-native/Libraries/Core/registerCallableModule.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,16 @@ type RegisterCallableModule = (
1616
moduleOrFactory: Module | (void => Module),
1717
) => void;
1818

19-
const registerCallableModule: RegisterCallableModule = (function () {
20-
if (global.RN$Bridgeless === true) {
21-
return (name, moduleOrFactory) => {
22-
if (typeof moduleOrFactory === 'function') {
23-
global.RN$registerCallableModule(name, moduleOrFactory);
24-
return;
25-
}
26-
27-
global.RN$registerCallableModule(name, () => moduleOrFactory);
28-
};
19+
const registerCallableModule: RegisterCallableModule = (
20+
name,
21+
moduleOrFactory,
22+
) => {
23+
if (typeof moduleOrFactory === 'function') {
24+
global.RN$registerCallableModule(name, moduleOrFactory);
25+
return;
2926
}
3027

31-
const BatchedBridge = require('../BatchedBridge/BatchedBridge').default;
32-
return (name, moduleOrFactory) => {
33-
if (typeof moduleOrFactory === 'function') {
34-
BatchedBridge.registerLazyCallableModule(name, moduleOrFactory);
35-
return;
36-
}
37-
38-
BatchedBridge.registerCallableModule(name, moduleOrFactory);
39-
};
40-
})();
28+
global.RN$registerCallableModule(name, () => moduleOrFactory);
29+
};
4130

4231
export default registerCallableModule;

packages/react-native/Libraries/Core/setUpBatchedBridge.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
import registerModule from './registerCallableModule';
1414

1515
registerModule('Systrace', () => require('../Performance/Systrace'));
16-
if (!(global.RN$Bridgeless === true)) {
17-
registerModule('JSTimers', () => require('./Timers/JSTimers').default);
18-
}
1916
registerModule('RCTLog', () => require('../Utilities/RCTLog').default);
2017
registerModule(
2118
'RCTDeviceEventEmitter',

packages/react-native/Libraries/Core/setUpTimers.js

Lines changed: 37 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,86 +19,40 @@ if (__DEV__) {
1919
}
2020

2121
// In bridgeless mode, timers are host functions installed from cpp.
22-
if (global.RN$Bridgeless === true) {
23-
// This is the flag that tells React to use `queueMicrotask` to batch state
24-
// updates, instead of using the scheduler to schedule a regular task.
25-
// We use a global variable because we don't currently have any other
26-
// mechanism to pass feature flags from RN to React in OSS.
27-
global.RN$enableMicrotasksInReact = true;
28-
29-
polyfillGlobal(
30-
'queueMicrotask',
31-
() =>
32-
require('../../src/private/webapis/microtasks/specs/NativeMicrotasks')
33-
.default.queueMicrotask,
34-
);
35-
36-
// We shim the immediate APIs via `queueMicrotask` to maintain the backward
37-
// compatibility.
38-
polyfillGlobal(
39-
'setImmediate',
40-
() => require('./Timers/immediateShim').setImmediate,
41-
);
42-
polyfillGlobal(
43-
'clearImmediate',
44-
() => require('./Timers/immediateShim').clearImmediate,
45-
);
46-
47-
polyfillGlobal(
48-
'requestIdleCallback',
49-
() =>
50-
require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks')
51-
.default.requestIdleCallback,
52-
);
53-
54-
polyfillGlobal(
55-
'cancelIdleCallback',
56-
() =>
57-
require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks')
58-
.default.cancelIdleCallback,
59-
);
60-
} else {
61-
/**
62-
* Set up timers.
63-
* You can use this module directly, or just require InitializeCore.
64-
*/
65-
const defineLazyTimer = (
66-
name:
67-
| 'cancelAnimationFrame'
68-
| 'cancelIdleCallback'
69-
| 'clearInterval'
70-
| 'clearTimeout'
71-
| 'requestAnimationFrame'
72-
| 'requestIdleCallback'
73-
| 'setInterval'
74-
| 'setTimeout',
75-
) => {
76-
polyfillGlobal(name, () => require('./Timers/JSTimers').default[name]);
77-
};
78-
defineLazyTimer('setTimeout');
79-
defineLazyTimer('clearTimeout');
80-
defineLazyTimer('setInterval');
81-
defineLazyTimer('clearInterval');
82-
defineLazyTimer('requestAnimationFrame');
83-
defineLazyTimer('cancelAnimationFrame');
84-
defineLazyTimer('requestIdleCallback');
85-
defineLazyTimer('cancelIdleCallback');
86-
87-
// Polyfill it with promise (regardless it's polyfilled or native) otherwise.
88-
polyfillGlobal(
89-
'queueMicrotask',
90-
() => require('./Timers/queueMicrotask.js').default,
91-
);
92-
93-
// When promise was polyfilled hence is queued to the RN microtask queue,
94-
// we polyfill the immediate APIs as aliases to the ReactNativeMicrotask APIs.
95-
// Note that in bridgeless mode, immediate APIs are installed from cpp.
96-
polyfillGlobal(
97-
'setImmediate',
98-
() => require('./Timers/JSTimers').default.queueReactNativeMicrotask,
99-
);
100-
polyfillGlobal(
101-
'clearImmediate',
102-
() => require('./Timers/JSTimers').default.clearReactNativeMicrotask,
103-
);
104-
}
22+
// This is the flag that tells React to use `queueMicrotask` to batch state
23+
// updates, instead of using the scheduler to schedule a regular task.
24+
// We use a global variable because we don't currently have any other
25+
// mechanism to pass feature flags from RN to React in OSS.
26+
global.RN$enableMicrotasksInReact = true;
27+
28+
polyfillGlobal(
29+
'queueMicrotask',
30+
() =>
31+
require('../../src/private/webapis/microtasks/specs/NativeMicrotasks')
32+
.default.queueMicrotask,
33+
);
34+
35+
// We shim the immediate APIs via `queueMicrotask` to maintain the backward
36+
// compatibility.
37+
polyfillGlobal(
38+
'setImmediate',
39+
() => require('./Timers/immediateShim').setImmediate,
40+
);
41+
polyfillGlobal(
42+
'clearImmediate',
43+
() => require('./Timers/immediateShim').clearImmediate,
44+
);
45+
46+
polyfillGlobal(
47+
'requestIdleCallback',
48+
() =>
49+
require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks')
50+
.default.requestIdleCallback,
51+
);
52+
53+
polyfillGlobal(
54+
'cancelIdleCallback',
55+
() =>
56+
require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks')
57+
.default.cancelIdleCallback,
58+
);

packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function get<Config extends {...}>(
5454
): HostComponent<Config> {
5555
ReactNativeViewConfigRegistry.register(name, () => {
5656
const {native, verify} = getRuntimeConfig?.(name) ?? {
57-
native: !global.RN$Bridgeless,
57+
native: false,
5858
verify: false,
5959
};
6060

packages/react-native/Libraries/ReactNative/UIManager.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ import type {UIManagerJSInterface} from '../Types/UIManagerJSInterface';
1313
import {getFabricUIManager} from './FabricUIManager';
1414
import nullthrows from 'nullthrows';
1515

16+
const UIManagerImpl: UIManagerJSInterface =
17+
require('./BridgelessUIManager').default;
18+
1619
function isFabricReactTag(reactTag: number): boolean {
1720
// React reserves even numbers for Fabric.
1821
return reactTag % 2 === 0;
1922
}
2023

21-
const UIManagerImpl: UIManagerJSInterface =
22-
global.RN$Bridgeless === true
23-
? require('./BridgelessUIManager').default
24-
: require('./PaperUIManager').default;
25-
2624
// $FlowFixMe[cannot-spread-interface]
2725
const UIManager: UIManagerJSInterface = {
2826
...UIManagerImpl,

packages/react-native/Libraries/Text/TextNativeComponent.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {TextProps} from './TextProps';
1515

1616
import {enablePreparedTextLayout} from '../../src/private/featureflags/ReactNativeFeatureFlags';
1717
import {createViewConfig} from '../NativeComponent/ViewConfig';
18-
import UIManager from '../ReactNative/UIManager';
1918
import createReactNativeComponentClass from '../Renderer/shims/createReactNativeComponentClass';
2019

2120
export type NativeTextProps = Readonly<{
@@ -82,11 +81,9 @@ export const NativeText: HostComponent<NativeTextProps> =
8281
) as any;
8382

8483
export const NativeVirtualText: HostComponent<NativeTextProps> =
85-
!global.RN$Bridgeless && !UIManager.hasViewManagerConfig('RCTVirtualText')
86-
? NativeText
87-
: (createReactNativeComponentClass('RCTVirtualText', () =>
88-
createViewConfig(virtualTextViewConfig),
89-
) as any);
84+
createReactNativeComponentClass('RCTVirtualText', () =>
85+
createViewConfig(virtualTextViewConfig),
86+
) as any;
9087

9188
export const NativeSelectableText: HostComponent<NativeTextProps> =
9289
enablePreparedTextLayout()

packages/react-native/Libraries/Utilities/__tests__/codegenNativeComponent-test.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ jest
3131
describe('codegenNativeComponent', () => {
3232
beforeEach(() => {
3333
jest.restoreAllMocks();
34-
// $FlowExpectedError[cannot-write]
35-
global.RN$Bridgeless = false;
3634
jest.spyOn(console, 'warn').mockImplementation(() => {});
3735
});
3836

@@ -75,16 +73,7 @@ describe('codegenNativeComponent', () => {
7573
);
7674
});
7775

78-
it('should NOT warn if called directly in BRIDGE mode', () => {
79-
// $FlowExpectedError[cannot-write]
80-
global.RN$Bridgeless = false;
81-
codegenNativeComponent<$FlowFixMe>('ComponentName');
82-
expect(console.warn).not.toHaveBeenCalled();
83-
});
84-
85-
it('should warn if called directly in BRIDGELESS mode', () => {
86-
// $FlowExpectedError[cannot-write]
87-
global.RN$Bridgeless = true;
76+
it('should warn if called directly', () => {
8877
codegenNativeComponent<$FlowFixMe>('ComponentName');
8978
expect(console.warn).toHaveBeenCalledWith(
9079
`Codegen didn't run for ComponentName. This will be an error in the future. Make sure you are using @react-native/babel-preset when building your JavaScript code.`,

packages/react-native/Libraries/Utilities/codegenNativeComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function codegenNativeComponent<Props extends {...}>(
3535
componentName: string,
3636
options?: NativeComponentOptions,
3737
): NativeComponentType<Props> {
38-
if (global.RN$Bridgeless === true && __DEV__) {
38+
if (__DEV__) {
3939
console.warn(
4040
`Codegen didn't run for ${componentName}. This will be an error in the future. Make sure you are using @react-native/babel-preset when building your JavaScript code.`,
4141
);

0 commit comments

Comments
 (0)