@samitouri / QOS-React-2 / commits / a0d991fe65

Re-land #22292 (remove uMS from open source build) (#22664)

I had to revert #22292 because there are some internal callers of useMutableSource that we haven't migrated yet. This removes useMutableSource from the open source build but keeps it in the internal one.

Andrew Clark committed Nov 1, 2021 at 00:39 UTC a0d991fe6587ad1cd1a97230f62f82c7cb6b9a40
16 files changed +80 -2
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js
+1
@@ -1018,6 +1018,7 @@ describe('ReactHooksInspectionIntegration', () => {
1018 ]);
1019 });
1020
1021 + // @gate enableUseMutableSource
1022 it('should support composite useMutableSource hook', () => {
1023 const createMutableSource =
1024 React.createMutableSource || React.unstable_createMutableSource;
packages/react-reconciler/src/ReactFiberHooks.new.js
+13
@@ -31,6 +31,7 @@ import {
31 enableStrictEffects,
32 enableLazyContextPropagation,
33 enableSuspenseLayoutEffectSemantics,
34 + enableUseMutableSource,
35 } from 'shared/ReactFeatureFlags';
36
37 import {
@@ -1052,6 +1053,10 @@ function useMutableSource<Source, Snapshot>(
1053 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1054 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1055 ): Snapshot {
1056 + if (!enableUseMutableSource) {
1057 + return (undefined: any);
1058 + }
1059 +
1060 const root = ((getWorkInProgressRoot(): any): FiberRoot);
1061
1062 if (root === null) {
@@ -1213,6 +1218,10 @@ function mountMutableSource<Source, Snapshot>(
1218 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1219 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1220 ): Snapshot {
1221 + if (!enableUseMutableSource) {
1222 + return (undefined: any);
1223 + }
1224 +
1225 const hook = mountWorkInProgressHook();
1226 hook.memoizedState = ({
1227 refs: {
@@ -1230,6 +1239,10 @@ function updateMutableSource<Source, Snapshot>(
1239 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1240 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1241 ): Snapshot {
1242 + if (!enableUseMutableSource) {
1243 + return (undefined: any);
1244 + }
1245 +
1246 const hook = updateWorkInProgressHook();
1247 return useMutableSource(hook, source, getSnapshot, subscribe);
1248 }
packages/react-reconciler/src/ReactFiberHooks.old.js
+13
@@ -31,6 +31,7 @@ import {
31 enableStrictEffects,
32 enableLazyContextPropagation,
33 enableSuspenseLayoutEffectSemantics,
34 + enableUseMutableSource,
35 } from 'shared/ReactFeatureFlags';
36
37 import {
@@ -1052,6 +1053,10 @@ function useMutableSource<Source, Snapshot>(
1053 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1054 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1055 ): Snapshot {
1056 + if (!enableUseMutableSource) {
1057 + return (undefined: any);
1058 + }
1059 +
1060 const root = ((getWorkInProgressRoot(): any): FiberRoot);
1061
1062 if (root === null) {
@@ -1213,6 +1218,10 @@ function mountMutableSource<Source, Snapshot>(
1218 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1219 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1220 ): Snapshot {
1221 + if (!enableUseMutableSource) {
1222 + return (undefined: any);
1223 + }
1224 +
1225 const hook = mountWorkInProgressHook();
1226 hook.memoizedState = ({
1227 refs: {
@@ -1230,6 +1239,10 @@ function updateMutableSource<Source, Snapshot>(
1239 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
1240 subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
1241 ): Snapshot {
1242 + if (!enableUseMutableSource) {
1243 + return (undefined: any);
1244 + }
1245 +
1246 const hook = updateWorkInProgressHook();
1247 return useMutableSource(hook, source, getSnapshot, subscribe);
1248 }
packages/react-reconciler/src/__tests__/useMutableSource-test.internal.js
+31
@@ -141,6 +141,7 @@ describe('useMutableSource', () => {
141
142 beforeEach(loadModules);
143
144 + // @gate enableUseMutableSource
145 it('should subscribe to a source and schedule updates when it changes', () => {
146 const source = createSource('one');
147 const mutableSource = createMutableSource(source, param => param.version);
@@ -208,6 +209,7 @@ describe('useMutableSource', () => {
209 });
210 });
211
212 + // @gate enableUseMutableSource
213 it('should restart work if a new source is mutated during render', () => {
214 const source = createSource('one');
215 const mutableSource = createMutableSource(source, param => param.version);
@@ -263,6 +265,7 @@ describe('useMutableSource', () => {
265 });
266 });
267
268 + // @gate enableUseMutableSource
269 it('should schedule an update if a new source is mutated between render and commit (subscription)', () => {
270 const source = createSource('one');
271 const mutableSource = createMutableSource(source, param => param.version);
@@ -302,6 +305,7 @@ describe('useMutableSource', () => {
305 });
306 });
307
308 + // @gate enableUseMutableSource
309 it('should unsubscribe and resubscribe if a new source is used', () => {
310 const sourceA = createSource('a-one');
311 const mutableSourceA = createMutableSource(
@@ -358,6 +362,7 @@ describe('useMutableSource', () => {
362 });
363 });
364
365 + // @gate enableUseMutableSource
366 it('should unsubscribe and resubscribe if a new subscribe function is provided', () => {
367 const source = createSource('a-one');
368 const mutableSource = createMutableSource(source, param => param.version);
@@ -422,6 +427,7 @@ describe('useMutableSource', () => {
427 });
428 });
429
430 + // @gate enableUseMutableSource
431 it('should re-use previously read snapshot value when reading is unsafe', () => {
432 const source = createSource('one');
433 const mutableSource = createMutableSource(source, param => param.version);
@@ -484,6 +490,7 @@ describe('useMutableSource', () => {
490 });
491 });
492
493 + // @gate enableUseMutableSource
494 it('should read from source on newly mounted subtree if no pending updates are scheduled for source', () => {
495 const source = createSource('one');
496 const mutableSource = createMutableSource(source, param => param.version);
@@ -523,6 +530,7 @@ describe('useMutableSource', () => {
530 });
531 });
532
533 + // @gate enableUseMutableSource
534 it('should throw and restart render if source and snapshot are unavailable during an update', () => {
535 const source = createSource('one');
536 const mutableSource = createMutableSource(source, param => param.version);
@@ -586,6 +594,7 @@ describe('useMutableSource', () => {
594 });
595 });
596
597 + // @gate enableUseMutableSource
598 it('should throw and restart render if source and snapshot are unavailable during a sync update', () => {
599 const source = createSource('one');
600 const mutableSource = createMutableSource(source, param => param.version);
@@ -649,6 +658,7 @@ describe('useMutableSource', () => {
658 });
659 });
660
661 + // @gate enableUseMutableSource
662 it('should only update components whose subscriptions fire', () => {
663 const source = createComplexSource('a:one', 'b:one');
664 const mutableSource = createMutableSource(source, param => param.version);
@@ -687,6 +697,7 @@ describe('useMutableSource', () => {
697 });
698 });
699
700 + // @gate enableUseMutableSource
701 it('should detect tearing in part of the store not yet subscribed to', () => {
702 const source = createComplexSource('a:one', 'b:one');
703 const mutableSource = createMutableSource(source, param => param.version);
@@ -779,6 +790,7 @@ describe('useMutableSource', () => {
790 });
791 });
792
793 + // @gate enableUseMutableSource
794 it('does not schedule an update for subscriptions that fire with an unchanged snapshot', () => {
795 const MockComponent = jest.fn(Component);
796
@@ -805,6 +817,7 @@ describe('useMutableSource', () => {
817 });
818 });
819
820 + // @gate enableUseMutableSource
821 it('should throw and restart if getSnapshot changes between scheduled update and re-render', () => {
822 const source = createSource('one');
823 const mutableSource = createMutableSource(source, param => param.version);
@@ -845,6 +858,7 @@ describe('useMutableSource', () => {
858 });
859 });
860
861 + // @gate enableUseMutableSource
862 it('should recover from a mutation during yield when other work is scheduled', () => {
863 const source = createSource('one');
864 const mutableSource = createMutableSource(source, param => param.version);
@@ -899,6 +913,7 @@ describe('useMutableSource', () => {
913 });
914 });
915
916 + // @gate enableUseMutableSource
917 it('should not throw if the new getSnapshot returns the same snapshot value', () => {
918 const source = createSource('one');
919 const mutableSource = createMutableSource(source, param => param.version);
@@ -953,6 +968,7 @@ describe('useMutableSource', () => {
968 });
969 });
970
971 + // @gate enableUseMutableSource
972 it('should not throw if getSnapshot changes but the source can be safely read from anyway', () => {
973 const source = createSource('one');
974 const mutableSource = createMutableSource(source, param => param.version);
@@ -992,6 +1008,7 @@ describe('useMutableSource', () => {
1008 });
1009 });
1010
1011 + // @gate enableUseMutableSource
1012 it('should still schedule an update if an eager selector throws after a mutation', () => {
1013 const source = createSource({
1014 friends: [
@@ -1058,6 +1075,7 @@ describe('useMutableSource', () => {
1075 });
1076 });
1077
1078 + // @gate enableUseMutableSource
1079 it('should not warn about updates that fire between unmount and passive unsubscribe', () => {
1080 const source = createSource('one');
1081 const mutableSource = createMutableSource(source, param => param.version);
@@ -1094,6 +1112,7 @@ describe('useMutableSource', () => {
1112 });
1113 });
1114
1115 + // @gate enableUseMutableSource
1116 it('should support inline selectors and updates that are processed after selector change', async () => {
1117 const source = createSource({
1118 a: 'initial',
@@ -1138,6 +1157,7 @@ describe('useMutableSource', () => {
1157 expect(root).toMatchRenderedOutput('Another update');
1158 });
1159
1160 + // @gate enableUseMutableSource
1161 it('should clear the update queue when getSnapshot changes with pending lower priority updates', async () => {
1162 const source = createSource({
1163 a: 'initial',
@@ -1194,6 +1214,7 @@ describe('useMutableSource', () => {
1214 expect(root).toMatchRenderedOutput('B: Update');
1215 });
1216
1217 + // @gate enableUseMutableSource
1218 it('should clear the update queue when source changes with pending lower priority updates', async () => {
1219 const sourceA = createSource('initial');
1220 const sourceB = createSource('initial');
@@ -1238,6 +1259,7 @@ describe('useMutableSource', () => {
1259 expect(root).toMatchRenderedOutput('B: Update');
1260 });
1261
1262 + // @gate enableUseMutableSource
1263 it('should always treat reading as potentially unsafe when getSnapshot changes between renders', async () => {
1264 const source = createSource({
1265 a: 'foo',
@@ -1327,6 +1349,7 @@ describe('useMutableSource', () => {
1349 expect(Scheduler).toHaveYielded(['x: bar, y: bar']);
1350 });
1351
1352 + // @gate enableUseMutableSource
1353 it('getSnapshot changes and then source is mutated in between paint and passive effect phase', async () => {
1354 const source = createSource({
1355 a: 'foo',
@@ -1385,6 +1408,7 @@ describe('useMutableSource', () => {
1408 expect(root).toMatchRenderedOutput('baz');
1409 });
1410
1411 + // @gate enableUseMutableSource
1412 it('getSnapshot changes and then source is mutated in between paint and passive effect phase, case 2', async () => {
1413 const source = createSource({
1414 a: 'a0',
@@ -1455,6 +1479,7 @@ describe('useMutableSource', () => {
1479 expect(root.getChildrenAsJSX()).toEqual('first: a1, second: a1');
1480 });
1481
1482 + // @gate enableUseMutableSource
1483 it(
1484 'if source is mutated after initial read but before subscription is set ' +
1485 'up, should still entangle all pending mutations even if snapshot of ' +
@@ -1559,6 +1584,7 @@ describe('useMutableSource', () => {
1584 },
1585 );
1586
1587 + // @gate enableUseMutableSource
1588 it('warns about functions being used as snapshot values', async () => {
1589 const source = createSource(() => 'a');
1590 const mutableSource = createMutableSource(source, param => param.version);
@@ -1586,6 +1612,7 @@ describe('useMutableSource', () => {
1612 expect(root).toMatchRenderedOutput('a');
1613 });
1614
1615 + // @gate enableUseMutableSource
1616 it('getSnapshot changes and then source is mutated during interleaved event', async () => {
1617 const {useEffect} = React;
1618
@@ -1710,6 +1737,7 @@ describe('useMutableSource', () => {
1737 });
1738 });
1739
1740 + // @gate enableUseMutableSource
1741 it('should not tear with newly mounted component when updates were scheduled at a lower priority', async () => {
1742 const source = createSource('one');
1743 const mutableSource = createMutableSource(source, param => param.version);
@@ -1789,6 +1817,7 @@ describe('useMutableSource', () => {
1817
1818 if (__DEV__) {
1819 describe('dev warnings', () => {
1820 + // @gate enableUseMutableSource
1821 it('should warn if the subscribe function does not return an unsubscribe function', () => {
1822 const source = createSource('one');
1823 const mutableSource = createMutableSource(
@@ -1814,6 +1843,7 @@ describe('useMutableSource', () => {
1843 );
1844 });
1845
1846 + // @gate enableUseMutableSource
1847 it('should error if multiple renderers of the same type use a mutable source at the same time', () => {
1848 const source = createSource('one');
1849 const mutableSource = createMutableSource(
@@ -1894,6 +1924,7 @@ describe('useMutableSource', () => {
1924 });
1925 });
1926
1927 + // @gate enableUseMutableSource
1928 it('should error if multiple renderers of the same type use a mutable source at the same time with mutation between', () => {
1929 const source = createSource('one');
1930 const mutableSource = createMutableSource(
packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js
+5
@@ -144,6 +144,7 @@ describe('useMutableSourceHydration', () => {
144 return <div>{`${label}:${snapshot}`}</div>;
145 }
146
147 + // @gate enableUseMutableSource
148 it('should render and hydrate', () => {
149 const source = createSource('one');
150 const mutableSource = createMutableSource(source, param => param.version);
@@ -180,6 +181,7 @@ describe('useMutableSourceHydration', () => {
181 expect(source.listenerCount).toBe(1);
182 });
183
184 + // @gate enableUseMutableSource
185 it('should detect a tear before hydrating a component', () => {
186 const source = createSource('one');
187 const mutableSource = createMutableSource(source, param => param.version);
@@ -224,6 +226,7 @@ describe('useMutableSourceHydration', () => {
226 expect(source.listenerCount).toBe(1);
227 });
228
229 + // @gate enableUseMutableSource
230 it('should detect a tear between hydrating components', () => {
231 const source = createSource('one');
232 const mutableSource = createMutableSource(source, param => param.version);
@@ -282,6 +285,7 @@ describe('useMutableSourceHydration', () => {
285 expect(source.listenerCount).toBe(2);
286 });
287
288 + // @gate enableUseMutableSource
289 it('should detect a tear between hydrating components reading from different parts of a source', () => {
290 const source = createComplexSource('a:one', 'b:one');
291 const mutableSource = createMutableSource(source, param => param.version);
@@ -371,6 +375,7 @@ describe('useMutableSourceHydration', () => {
375 });
376
377 // @gate !enableSyncDefaultUpdates
378 + // @gate enableUseMutableSource
379 it('should detect a tear during a higher priority interruption', () => {
380 const source = createSource('one');
381 const mutableSource = createMutableSource(source, param => param.version);
packages/react/index.experimental.js
-1
@@ -46,7 +46,6 @@ export {
46 useInsertionEffect,
47 useLayoutEffect,
48 useMemo,
49 - useMutableSource as unstable_useMutableSource,
49 useSyncExternalStore,
50 useReducer,
51 useRef,
packages/react/index.stable.js
-1
@@ -39,7 +39,6 @@ export {
39 useInsertionEffect,
40 useLayoutEffect,
41 useMemo,
42 - useMutableSource as unstable_useMutableSource,
42 useSyncExternalStore,
43 useReducer,
44 useRef,
packages/shared/ReactFeatureFlags.js
+3
@@ -185,3 +185,6 @@ export const allowConcurrentByDefault = false;
185 export const enablePersistentOffscreenHostContainer = false;
186
187 export const consoleManagedByDevToolsDuringStrictMode = true;
188 +
189 +// Only enabled in www builds
190 +export const enableUseMutableSource = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
+1
@@ -74,6 +74,7 @@ export const enableSyncDefaultUpdates = true;
74 export const allowConcurrentByDefault = true;
75
76 export const consoleManagedByDevToolsDuringStrictMode = false;
77 +export const enableUseMutableSource = false;
78
79 // Flow magic to verify the exports of this file match the original version.
80 // eslint-disable-next-line no-unused-vars
packages/shared/forks/ReactFeatureFlags.native-oss.js
+1
@@ -66,6 +66,7 @@ export const allowConcurrentByDefault = false;
66 export const enablePersistentOffscreenHostContainer = false;
67
68 export const consoleManagedByDevToolsDuringStrictMode = false;
69 +export const enableUseMutableSource = false;
70
71 // Flow magic to verify the exports of this file match the original version.
72 // eslint-disable-next-line no-unused-vars
packages/shared/forks/ReactFeatureFlags.test-renderer.js
+1
@@ -66,6 +66,7 @@ export const allowConcurrentByDefault = false;
66 export const enablePersistentOffscreenHostContainer = false;
67
68 export const consoleManagedByDevToolsDuringStrictMode = false;
69 +export const enableUseMutableSource = false;
70
71 // Flow magic to verify the exports of this file match the original version.
72 // eslint-disable-next-line no-unused-vars
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
+1
@@ -65,6 +65,7 @@ export const allowConcurrentByDefault = true;
65 export const enablePersistentOffscreenHostContainer = false;
66
67 export const consoleManagedByDevToolsDuringStrictMode = false;
68 +export const enableUseMutableSource = false;
69
70 // Flow magic to verify the exports of this file match the original version.
71 // eslint-disable-next-line no-unused-vars
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
+3
@@ -67,6 +67,9 @@ export const enablePersistentOffscreenHostContainer = false;
67
68 export const consoleManagedByDevToolsDuringStrictMode = false;
69
70 +// Some www surfaces are still using this. Remove once they have been migrated.
71 +export const enableUseMutableSource = true;
72 +
73 // Flow magic to verify the exports of this file match the original version.
74 // eslint-disable-next-line no-unused-vars
75 type Check<_X, Y: _X, X: Y = _X> = null;
packages/shared/forks/ReactFeatureFlags.testing.js
+1
@@ -66,6 +66,7 @@ export const allowConcurrentByDefault = false;
66 export const enablePersistentOffscreenHostContainer = false;
67
68 export const consoleManagedByDevToolsDuringStrictMode = false;
69 +export const enableUseMutableSource = false;
70
71 // Flow magic to verify the exports of this file match the original version.
72 // eslint-disable-next-line no-unused-vars
packages/shared/forks/ReactFeatureFlags.testing.www.js
+3
@@ -67,6 +67,9 @@ export const enablePersistentOffscreenHostContainer = false;
67
68 export const consoleManagedByDevToolsDuringStrictMode = false;
69
70 +// Some www surfaces are still using this. Remove once they have been migrated.
71 +export const enableUseMutableSource = true;
72 +
73 // Flow magic to verify the exports of this file match the original version.
74 // eslint-disable-next-line no-unused-vars
75 type Check<_X, Y: _X, X: Y = _X> = null;
packages/shared/forks/ReactFeatureFlags.www.js
+3
@@ -102,6 +102,9 @@ export const enablePersistentOffscreenHostContainer = false;
102
103 export const consoleManagedByDevToolsDuringStrictMode = true;
104
105 +// Some www surfaces are still using this. Remove once they have been migrated.
106 +export const enableUseMutableSource = true;
107 +
108 // Flow magic to verify the exports of this file match the original version.
109 // eslint-disable-next-line no-unused-vars
110 type Check<_X, Y: _X, X: Y = _X> = null;