Skip to content

Commit d13bb69

Browse files
committed
Update ART to concurrent, RN and Noop to error
1 parent e27d5bb commit d13bb69

21 files changed

+108
-35
lines changed

packages/react-art/src/ReactART.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import * as React from 'react';
99
import ReactVersion from 'shared/ReactVersion';
10-
import {LegacyRoot} from 'react-reconciler/src/ReactRootTags';
10+
import {ConcurrentRoot} from 'react-reconciler/src/ReactRootTags';
1111
import {
1212
createContainer,
1313
updateContainer,
1414
injectIntoDevTools,
15+
flushSync,
1516
} from 'react-reconciler/src/ReactFiberReconciler';
1617
import Transform from 'art/core/transform';
1718
import Mode from 'art/modes/current';
@@ -68,13 +69,15 @@ class Surface extends React.Component {
6869

6970
this._mountNode = createContainer(
7071
this._surface,
71-
LegacyRoot,
72+
ConcurrentRoot,
7273
null,
7374
false,
7475
false,
7576
'',
7677
);
77-
updateContainer(this.props.children, this._mountNode, this);
78+
flushSync(() => {
79+
updateContainer(this.props.children, this._mountNode, this);
80+
});
7881
}
7982

8083
componentDidUpdate(prevProps, prevState) {
@@ -84,15 +87,19 @@ class Surface extends React.Component {
8487
this._surface.resize(+props.width, +props.height);
8588
}
8689

87-
updateContainer(this.props.children, this._mountNode, this);
90+
flushSync(() => {
91+
updateContainer(this.props.children, this._mountNode, this);
92+
});
8893

8994
if (this._surface.render) {
9095
this._surface.render();
9196
}
9297
}
9398

9499
componentWillUnmount() {
95-
updateContainer(null, this._mountNode, this);
100+
flushSync(() => {
101+
updateContainer(null, this._mountNode, this);
102+
});
96103
}
97104

98105
render() {

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: 7 additions & 0 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,6 +123,7 @@ 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];
@@ -143,6 +145,7 @@ it('fails if unknown/unsupported event types are dispatched', () => {
143145
}).toThrow('Unsupported top level event type "unspecifiedEvent" dispatched');
144146
});
145147

148+
// @gate !disableLegacyMode
146149
it('handles events', () => {
147150
expect(RCTEventEmitter.register).toHaveBeenCalledTimes(1);
148151
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
@@ -200,6 +203,7 @@ it('handles events', () => {
200203
});
201204

202205
// @gate !disableLegacyContext || !__DEV__
206+
// @gate !disableLegacyMode
203207
it('handles events on text nodes', () => {
204208
expect(RCTEventEmitter.register).toHaveBeenCalledTimes(1);
205209
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
@@ -283,6 +287,7 @@ it('handles events on text nodes', () => {
283287
]);
284288
});
285289

290+
// @gate !disableLegacyMode
286291
it('handles when a responder is unmounted while a touch sequence is in progress', () => {
287292
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
288293
const View = fakeRequireNativeComponent('View', {id: true});
@@ -372,6 +377,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress'
372377
expect(log).toEqual(['two responder start']);
373378
});
374379

380+
// @gate !disableLegacyMode
375381
it('handles events without target', () => {
376382
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
377383

@@ -462,6 +468,7 @@ it('handles events without target', () => {
462468
]);
463469
});
464470

471+
// @gate !disableLegacyMode
465472
it('dispatches event with target as instance', () => {
466473
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
467474

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

Lines changed: 24 additions & 0 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},
@@ -433,6 +447,7 @@ describe('ReactNative', () => {
433447
expect(UIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
434448
});
435449

450+
// @gate !disableLegacyMode
436451
it('calls setState with no arguments', () => {
437452
let mockArgs;
438453
class Component extends React.Component {
@@ -448,6 +463,7 @@ describe('ReactNative', () => {
448463
expect(mockArgs.length).toEqual(0);
449464
});
450465

466+
// @gate !disableLegacyMode
451467
it('should not throw when <View> is used inside of a <Text> ancestor', () => {
452468
const Image = createReactNativeComponentClass('RCTImage', () => ({
453469
validAttributes: {},
@@ -478,6 +494,7 @@ describe('ReactNative', () => {
478494
);
479495
});
480496

497+
// @gate !disableLegacyMode
481498
it('should throw for text not inside of a <Text> ancestor', async () => {
482499
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
483500
validAttributes: {},
@@ -512,6 +529,7 @@ describe('ReactNative', () => {
512529
);
513530
});
514531

532+
// @gate !disableLegacyMode
515533
it('should not throw for text inside of an indirect <Text> ancestor', () => {
516534
const Text = createReactNativeComponentClass('RCTText', () => ({
517535
validAttributes: {},
@@ -528,6 +546,7 @@ describe('ReactNative', () => {
528546
);
529547
});
530548

549+
// @gate !disableLegacyMode
531550
it('findHostInstance_DEPRECATED should warn if used to find a host component inside StrictMode', () => {
532551
const View = createReactNativeComponentClass('RCTView', () => ({
533552
validAttributes: {foo: true},
@@ -564,6 +583,7 @@ describe('ReactNative', () => {
564583
expect(match).toBe(child);
565584
});
566585

586+
// @gate !disableLegacyMode
567587
it('findHostInstance_DEPRECATED should warn if passed a component that is inside StrictMode', () => {
568588
const View = createReactNativeComponentClass('RCTView', () => ({
569589
validAttributes: {foo: true},
@@ -601,6 +621,7 @@ describe('ReactNative', () => {
601621
expect(match).toBe(child);
602622
});
603623

624+
// @gate !disableLegacyMode
604625
it('findNodeHandle should warn if used to find a host component inside StrictMode', () => {
605626
const View = createReactNativeComponentClass('RCTView', () => ({
606627
validAttributes: {foo: true},
@@ -635,6 +656,7 @@ describe('ReactNative', () => {
635656
expect(match).toBe(child._nativeTag);
636657
});
637658

659+
// @gate !disableLegacyMode
638660
it('findNodeHandle should warn if passed a component that is inside StrictMode', () => {
639661
const View = createReactNativeComponentClass('RCTView', () => ({
640662
validAttributes: {foo: true},
@@ -670,6 +692,7 @@ describe('ReactNative', () => {
670692
expect(match).toBe(child._nativeTag);
671693
});
672694

695+
// @gate !disableLegacyMode
673696
it('blur on host component calls TextInputState', () => {
674697
const View = createReactNativeComponentClass('RCTView', () => ({
675698
validAttributes: {foo: true},
@@ -687,6 +710,7 @@ describe('ReactNative', () => {
687710
expect(TextInputState.blurTextInput).toHaveBeenCalledWith(viewRef.current);
688711
});
689712

713+
// @gate !disableLegacyMode
690714
it('focus on host component calls TextInputState', () => {
691715
const View = createReactNativeComponentClass('RCTView', () => ({
692716
validAttributes: {foo: true},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('createReactNativeComponentClass', () => {
2525
ReactNative = require('react-native-renderer');
2626
});
2727

28+
// @gate !disableLegacyMode
2829
it('should register viewConfigs', () => {
2930
const textViewConfig = {
3031
validAttributes: {},

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
ConcurrentRoot,
3333
LegacyRoot,
3434
} from 'react-reconciler/constants';
35-
import {enableRefAsProp} from 'shared/ReactFeatureFlags';
35+
import {enableRefAsProp, disableLegacyMode} from 'shared/ReactFeatureFlags';
3636

3737
type Container = {
3838
rootID: string,
@@ -1020,6 +1020,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
10201020
},
10211021

10221022
createLegacyRoot() {
1023+
if (disableLegacyMode) {
1024+
throw new Error('createLegacyRoot: Unsupported Legacy Mode API.');
1025+
}
1026+
10231027
const container = {
10241028
rootID: '' + idCounter++,
10251029
pendingChildren: [],
@@ -1119,6 +1123,9 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
11191123
},
11201124

11211125
renderLegacySyncRoot(element: React$Element<any>, callback: ?Function) {
1126+
if (disableLegacyMode) {
1127+
throw new Error('createLegacyRoot: Unsupported Legacy Mode API.');
1128+
}
11221129
const rootID = DEFAULT_ROOT_ID;
11231130
const container = ReactNoop.getOrCreateRootContainer(rootID, LegacyRoot);
11241131
const root = roots.get(container.rootID);

packages/react-reconciler/src/__tests__/Activity-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('Activity', () => {
118118
);
119119
});
120120

121-
// @gate www
121+
// @gate www && !disableLegacyMode
122122
it('does not defer in legacy mode', async () => {
123123
let setState;
124124
function Foo() {

0 commit comments

Comments
 (0)