Skip to content

Commit 23134e4

Browse files
sebmarkbageAndyPengc12
authored andcommitted
Use the disableLegacyMode where ever we check the ConcurrentMode mode (facebook#28657)
Saves some bytes and ensures that we're actually disabling it. Turns out this flag wasn't disabling React Native/Fabric, React Noop and React ART legacy modes so those are updated too. Should be rebased on facebook#28681.
1 parent 4d24105 commit 23134e4

33 files changed

+288
-149
lines changed

packages/react-native-renderer/src/ReactFabric.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {getPublicInstanceFromInternalInstanceHandle} from './ReactFiberConfigFab
4848

4949
// Module provided by RN:
5050
import {ReactFiberErrorDialog} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
51+
import {disableLegacyMode} from 'shared/ReactFeatureFlags';
5152

5253
if (typeof ReactFiberErrorDialog.showErrorDialog !== 'function') {
5354
throw new Error(
@@ -106,6 +107,10 @@ function render(
106107
callback: ?() => void,
107108
concurrentRoot: ?boolean,
108109
): ?ElementRef<ElementType> {
110+
if (disableLegacyMode && !concurrentRoot) {
111+
throw new Error('render: Unsupported Legacy Mode API.');
112+
}
113+
109114
let root = roots.get(containerTag);
110115

111116
if (!root) {

packages/react-native-renderer/src/ReactNativeRenderer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
isChildPublicInstance,
5151
} from './ReactNativePublicCompat';
5252

53+
import {disableLegacyMode} from 'shared/ReactFeatureFlags';
54+
5355
// Module provided by RN:
5456
import {ReactFiberErrorDialog} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
5557

@@ -109,6 +111,10 @@ function render(
109111
containerTag: number,
110112
callback: ?() => void,
111113
): ?ElementRef<ElementType> {
114+
if (disableLegacyMode) {
115+
throw new Error('render: Unsupported Legacy Mode API.');
116+
}
117+
112118
let root = roots.get(containerTag);
113119

114120
if (!root) {

packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('ReactNativeError', () => {
5050
);
5151
});
5252

53+
// @gate !disableLegacyMode
5354
it('should be able to extract a component stack from a native view', () => {
5455
const View = createReactNativeComponentClass('View', () => ({
5556
validAttributes: {foo: true},

packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ beforeEach(() => {
7979
.ReactNativeViewConfigRegistry.register;
8080
});
8181

82+
// @gate !disableLegacyMode
8283
it('fails to register the same event name with different types', async () => {
8384
const InvalidEvents = createReactNativeComponentClass('InvalidEvents', () => {
8485
if (!__DEV__) {
@@ -122,14 +123,18 @@ it('fails to register the same event name with different types', async () => {
122123
).rejects.toThrow('Event cannot be both direct and bubbling: topChange');
123124
});
124125

126+
// @gate !disableLegacyMode
125127
it('fails if unknown/unsupported event types are dispatched', () => {
126128
expect(RCTEventEmitter.register).toHaveBeenCalledTimes(1);
127129
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
128130
const View = fakeRequireNativeComponent('View', {});
129131

130132
ReactNative.render(<View onUnspecifiedEvent={() => {}} />, 1);
131133

132-
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
134+
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchInlineSnapshot(`
135+
"<native root> {}
136+
View null"
137+
`);
133138
expect(UIManager.createView).toHaveBeenCalledTimes(1);
134139

135140
const target = UIManager.createView.mock.calls[0][0];
@@ -143,6 +148,7 @@ it('fails if unknown/unsupported event types are dispatched', () => {
143148
}).toThrow('Unsupported top level event type "unspecifiedEvent" dispatched');
144149
});
145150

151+
// @gate !disableLegacyMode
146152
it('handles events', () => {
147153
expect(RCTEventEmitter.register).toHaveBeenCalledTimes(1);
148154
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
@@ -167,7 +173,11 @@ it('handles events', () => {
167173
1,
168174
);
169175

170-
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
176+
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchInlineSnapshot(`
177+
"<native root> {}
178+
View {"foo":"outer"}
179+
View {"foo":"inner"}"
180+
`);
171181
expect(UIManager.createView).toHaveBeenCalledTimes(2);
172182

173183
// Don't depend on the order of createView() calls.
@@ -200,6 +210,7 @@ it('handles events', () => {
200210
});
201211

202212
// @gate !disableLegacyContext || !__DEV__
213+
// @gate !disableLegacyMode
203214
it('handles events on text nodes', () => {
204215
expect(RCTEventEmitter.register).toHaveBeenCalledTimes(1);
205216
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
@@ -283,6 +294,7 @@ it('handles events on text nodes', () => {
283294
]);
284295
});
285296

297+
// @gate !disableLegacyMode
286298
it('handles when a responder is unmounted while a touch sequence is in progress', () => {
287299
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
288300
const View = fakeRequireNativeComponent('View', {id: true});
@@ -372,6 +384,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress'
372384
expect(log).toEqual(['two responder start']);
373385
});
374386

387+
// @gate !disableLegacyMode
375388
it('handles events without target', () => {
376389
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
377390

@@ -462,6 +475,7 @@ it('handles events without target', () => {
462475
]);
463476
});
464477

478+
// @gate !disableLegacyMode
465479
it('dispatches event with target as instance', () => {
466480
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
467481

packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('ReactNative', () => {
4545
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').TextInputState;
4646
});
4747

48+
// @gate !disableLegacyMode
4849
it('should be able to create and render a native component', () => {
4950
const View = createReactNativeComponentClass('RCTView', () => ({
5051
validAttributes: {foo: true},
@@ -58,6 +59,7 @@ describe('ReactNative', () => {
5859
expect(UIManager.updateView).not.toBeCalled();
5960
});
6061

62+
// @gate !disableLegacyMode
6163
it('should be able to create and update a native component', () => {
6264
const View = createReactNativeComponentClass('RCTView', () => ({
6365
validAttributes: {foo: true},
@@ -79,6 +81,7 @@ describe('ReactNative', () => {
7981
expect(UIManager.updateView).toBeCalledWith(3, 'RCTView', {foo: 'bar'});
8082
});
8183

84+
// @gate !disableLegacyMode
8285
it('should not call UIManager.updateView after render for properties that have not changed', () => {
8386
const Text = createReactNativeComponentClass('RCTText', () => ({
8487
validAttributes: {foo: true},
@@ -105,6 +108,7 @@ describe('ReactNative', () => {
105108
expect(UIManager.updateView).toHaveBeenCalledTimes(4);
106109
});
107110

111+
// @gate !disableLegacyMode
108112
it('should call dispatchCommand for native refs', () => {
109113
const View = createReactNativeComponentClass('RCTView', () => ({
110114
validAttributes: {foo: true},
@@ -133,6 +137,7 @@ describe('ReactNative', () => {
133137
);
134138
});
135139

140+
// @gate !disableLegacyMode
136141
it('should warn and no-op if calling dispatchCommand on non native refs', () => {
137142
class BasicClass extends React.Component {
138143
render() {
@@ -162,6 +167,7 @@ describe('ReactNative', () => {
162167
expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
163168
});
164169

170+
// @gate !disableLegacyMode
165171
it('should call sendAccessibilityEvent for native refs', () => {
166172
const View = createReactNativeComponentClass('RCTView', () => ({
167173
validAttributes: {foo: true},
@@ -192,6 +198,7 @@ describe('ReactNative', () => {
192198
).toHaveBeenCalledWith(expect.any(Number), 'focus');
193199
});
194200

201+
// @gate !disableLegacyMode
195202
it('should warn and no-op if calling sendAccessibilityEvent on non native refs', () => {
196203
class BasicClass extends React.Component {
197204
render() {
@@ -221,6 +228,7 @@ describe('ReactNative', () => {
221228
expect(UIManager.sendAccessibilityEvent).not.toBeCalled();
222229
});
223230

231+
// @gate !disableLegacyMode
224232
it('should not call UIManager.updateView from ref.setNativeProps for properties that have not changed', () => {
225233
const View = createReactNativeComponentClass('RCTView', () => ({
226234
validAttributes: {foo: true},
@@ -254,6 +262,7 @@ describe('ReactNative', () => {
254262
);
255263
});
256264

265+
// @gate !disableLegacyMode
257266
it('should call UIManager.measure on ref.measure', () => {
258267
const View = createReactNativeComponentClass('RCTView', () => ({
259268
validAttributes: {foo: true},
@@ -280,6 +289,7 @@ describe('ReactNative', () => {
280289
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100, 0, 0);
281290
});
282291

292+
// @gate !disableLegacyMode
283293
it('should call UIManager.measureInWindow on ref.measureInWindow', () => {
284294
const View = createReactNativeComponentClass('RCTView', () => ({
285295
validAttributes: {foo: true},
@@ -306,6 +316,7 @@ describe('ReactNative', () => {
306316
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100);
307317
});
308318

319+
// @gate !disableLegacyMode
309320
it('should support reactTag in ref.measureLayout', () => {
310321
const View = createReactNativeComponentClass('RCTView', () => ({
311322
validAttributes: {foo: true},
@@ -346,6 +357,7 @@ describe('ReactNative', () => {
346357
expect(successCallback).toHaveBeenCalledWith(1, 1, 100, 100);
347358
});
348359

360+
// @gate !disableLegacyMode
349361
it('should support ref in ref.measureLayout of host components', () => {
350362
const View = createReactNativeComponentClass('RCTView', () => ({
351363
validAttributes: {foo: true},
@@ -382,6 +394,7 @@ describe('ReactNative', () => {
382394
expect(successCallback).toHaveBeenCalledWith(1, 1, 100, 100);
383395
});
384396

397+
// @gate !disableLegacyMode
385398
it('returns the correct instance and calls it in the callback', () => {
386399
const View = createReactNativeComponentClass('RCTView', () => ({
387400
validAttributes: {foo: true},
@@ -403,6 +416,7 @@ describe('ReactNative', () => {
403416
expect(a).toBe(c);
404417
});
405418

419+
// @gate !disableLegacyMode
406420
it('renders and reorders children', () => {
407421
const View = createReactNativeComponentClass('RCTView', () => ({
408422
validAttributes: {title: true},
@@ -427,12 +441,59 @@ describe('ReactNative', () => {
427441
const after = 'mxhpgwfralkeoivcstzy';
428442

429443
ReactNative.render(<Component chars={before} />, 11);
430-
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
444+
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchInlineSnapshot(`
445+
"<native root> {}
446+
RCTView null
447+
RCTView {"title":"a"}
448+
RCTView {"title":"b"}
449+
RCTView {"title":"c"}
450+
RCTView {"title":"d"}
451+
RCTView {"title":"e"}
452+
RCTView {"title":"f"}
453+
RCTView {"title":"g"}
454+
RCTView {"title":"h"}
455+
RCTView {"title":"i"}
456+
RCTView {"title":"j"}
457+
RCTView {"title":"k"}
458+
RCTView {"title":"l"}
459+
RCTView {"title":"m"}
460+
RCTView {"title":"n"}
461+
RCTView {"title":"o"}
462+
RCTView {"title":"p"}
463+
RCTView {"title":"q"}
464+
RCTView {"title":"r"}
465+
RCTView {"title":"s"}
466+
RCTView {"title":"t"}"
467+
`);
431468

432469
ReactNative.render(<Component chars={after} />, 11);
433-
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
470+
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchInlineSnapshot(`
471+
"<native root> {}
472+
RCTView null
473+
RCTView {"title":"m"}
474+
RCTView {"title":"x"}
475+
RCTView {"title":"h"}
476+
RCTView {"title":"p"}
477+
RCTView {"title":"g"}
478+
RCTView {"title":"w"}
479+
RCTView {"title":"f"}
480+
RCTView {"title":"r"}
481+
RCTView {"title":"a"}
482+
RCTView {"title":"l"}
483+
RCTView {"title":"k"}
484+
RCTView {"title":"e"}
485+
RCTView {"title":"o"}
486+
RCTView {"title":"i"}
487+
RCTView {"title":"v"}
488+
RCTView {"title":"c"}
489+
RCTView {"title":"s"}
490+
RCTView {"title":"t"}
491+
RCTView {"title":"z"}
492+
RCTView {"title":"y"}"
493+
`);
434494
});
435495

496+
// @gate !disableLegacyMode
436497
it('calls setState with no arguments', () => {
437498
let mockArgs;
438499
class Component extends React.Component {
@@ -448,6 +509,7 @@ describe('ReactNative', () => {
448509
expect(mockArgs.length).toEqual(0);
449510
});
450511

512+
// @gate !disableLegacyMode
451513
it('should not throw when <View> is used inside of a <Text> ancestor', () => {
452514
const Image = createReactNativeComponentClass('RCTImage', () => ({
453515
validAttributes: {},
@@ -478,6 +540,7 @@ describe('ReactNative', () => {
478540
);
479541
});
480542

543+
// @gate !disableLegacyMode
481544
it('should throw for text not inside of a <Text> ancestor', async () => {
482545
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
483546
validAttributes: {},
@@ -512,6 +575,7 @@ describe('ReactNative', () => {
512575
);
513576
});
514577

578+
// @gate !disableLegacyMode
515579
it('should not throw for text inside of an indirect <Text> ancestor', () => {
516580
const Text = createReactNativeComponentClass('RCTText', () => ({
517581
validAttributes: {},
@@ -528,6 +592,7 @@ describe('ReactNative', () => {
528592
);
529593
});
530594

595+
// @gate !disableLegacyMode
531596
it('findHostInstance_DEPRECATED should warn if used to find a host component inside StrictMode', () => {
532597
const View = createReactNativeComponentClass('RCTView', () => ({
533598
validAttributes: {foo: true},
@@ -564,6 +629,7 @@ describe('ReactNative', () => {
564629
expect(match).toBe(child);
565630
});
566631

632+
// @gate !disableLegacyMode
567633
it('findHostInstance_DEPRECATED should warn if passed a component that is inside StrictMode', () => {
568634
const View = createReactNativeComponentClass('RCTView', () => ({
569635
validAttributes: {foo: true},
@@ -601,6 +667,7 @@ describe('ReactNative', () => {
601667
expect(match).toBe(child);
602668
});
603669

670+
// @gate !disableLegacyMode
604671
it('findNodeHandle should warn if used to find a host component inside StrictMode', () => {
605672
const View = createReactNativeComponentClass('RCTView', () => ({
606673
validAttributes: {foo: true},
@@ -635,6 +702,7 @@ describe('ReactNative', () => {
635702
expect(match).toBe(child._nativeTag);
636703
});
637704

705+
// @gate !disableLegacyMode
638706
it('findNodeHandle should warn if passed a component that is inside StrictMode', () => {
639707
const View = createReactNativeComponentClass('RCTView', () => ({
640708
validAttributes: {foo: true},
@@ -670,6 +738,7 @@ describe('ReactNative', () => {
670738
expect(match).toBe(child._nativeTag);
671739
});
672740

741+
// @gate !disableLegacyMode
673742
it('blur on host component calls TextInputState', () => {
674743
const View = createReactNativeComponentClass('RCTView', () => ({
675744
validAttributes: {foo: true},
@@ -687,6 +756,7 @@ describe('ReactNative', () => {
687756
expect(TextInputState.blurTextInput).toHaveBeenCalledWith(viewRef.current);
688757
});
689758

759+
// @gate !disableLegacyMode
690760
it('focus on host component calls TextInputState', () => {
691761
const View = createReactNativeComponentClass('RCTView', () => ({
692762
validAttributes: {foo: true},

packages/react-native-renderer/src/__tests__/__snapshots__/ReactNativeEvents-test.internal.js.snap

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)