Skip to content

Commit 710f411

Browse files
committed
Re-land facebook#22292 (remove uMS from open source build)
I had to revert facebook#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.
1 parent 6bce035 commit 710f411

16 files changed

+80
-2
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ describe('ReactHooksInspectionIntegration', () => {
10181018
]);
10191019
});
10201020

1021+
// @gate enableUseMutableSource
10211022
it('should support composite useMutableSource hook', () => {
10221023
const createMutableSource =
10231024
React.createMutableSource || React.unstable_createMutableSource;

packages/react-reconciler/src/ReactFiberHooks.new.js

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
enableStrictEffects,
3232
enableLazyContextPropagation,
3333
enableSuspenseLayoutEffectSemantics,
34+
enableUseMutableSource,
3435
} from 'shared/ReactFeatureFlags';
3536

3637
import {
@@ -1052,6 +1053,10 @@ function useMutableSource<Source, Snapshot>(
10521053
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
10531054
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
10541055
): Snapshot {
1056+
if (enableUseMutableSource) {
1057+
return (undefined: any);
1058+
}
1059+
10551060
const root = ((getWorkInProgressRoot(): any): FiberRoot);
10561061

10571062
if (root === null) {
@@ -1213,6 +1218,10 @@ function mountMutableSource<Source, Snapshot>(
12131218
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
12141219
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
12151220
): Snapshot {
1221+
if (enableUseMutableSource) {
1222+
return (undefined: any);
1223+
}
1224+
12161225
const hook = mountWorkInProgressHook();
12171226
hook.memoizedState = ({
12181227
refs: {
@@ -1230,6 +1239,10 @@ function updateMutableSource<Source, Snapshot>(
12301239
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
12311240
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
12321241
): Snapshot {
1242+
if (enableUseMutableSource) {
1243+
return (undefined: any);
1244+
}
1245+
12331246
const hook = updateWorkInProgressHook();
12341247
return useMutableSource(hook, source, getSnapshot, subscribe);
12351248
}

packages/react-reconciler/src/ReactFiberHooks.old.js

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
enableStrictEffects,
3232
enableLazyContextPropagation,
3333
enableSuspenseLayoutEffectSemantics,
34+
enableUseMutableSource,
3435
} from 'shared/ReactFeatureFlags';
3536

3637
import {
@@ -1052,6 +1053,10 @@ function useMutableSource<Source, Snapshot>(
10521053
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
10531054
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
10541055
): Snapshot {
1056+
if (enableUseMutableSource) {
1057+
return (undefined: any);
1058+
}
1059+
10551060
const root = ((getWorkInProgressRoot(): any): FiberRoot);
10561061

10571062
if (root === null) {
@@ -1213,6 +1218,10 @@ function mountMutableSource<Source, Snapshot>(
12131218
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
12141219
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
12151220
): Snapshot {
1221+
if (enableUseMutableSource) {
1222+
return (undefined: any);
1223+
}
1224+
12161225
const hook = mountWorkInProgressHook();
12171226
hook.memoizedState = ({
12181227
refs: {
@@ -1230,6 +1239,10 @@ function updateMutableSource<Source, Snapshot>(
12301239
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
12311240
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
12321241
): Snapshot {
1242+
if (enableUseMutableSource) {
1243+
return (undefined: any);
1244+
}
1245+
12331246
const hook = updateWorkInProgressHook();
12341247
return useMutableSource(hook, source, getSnapshot, subscribe);
12351248
}

packages/react-reconciler/src/__tests__/useMutableSource-test.internal.js

+31
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ describe('useMutableSource', () => {
141141

142142
beforeEach(loadModules);
143143

144+
// @gate enableUseMutableSource
144145
it('should subscribe to a source and schedule updates when it changes', () => {
145146
const source = createSource('one');
146147
const mutableSource = createMutableSource(source, param => param.version);
@@ -208,6 +209,7 @@ describe('useMutableSource', () => {
208209
});
209210
});
210211

212+
// @gate enableUseMutableSource
211213
it('should restart work if a new source is mutated during render', () => {
212214
const source = createSource('one');
213215
const mutableSource = createMutableSource(source, param => param.version);
@@ -263,6 +265,7 @@ describe('useMutableSource', () => {
263265
});
264266
});
265267

268+
// @gate enableUseMutableSource
266269
it('should schedule an update if a new source is mutated between render and commit (subscription)', () => {
267270
const source = createSource('one');
268271
const mutableSource = createMutableSource(source, param => param.version);
@@ -302,6 +305,7 @@ describe('useMutableSource', () => {
302305
});
303306
});
304307

308+
// @gate enableUseMutableSource
305309
it('should unsubscribe and resubscribe if a new source is used', () => {
306310
const sourceA = createSource('a-one');
307311
const mutableSourceA = createMutableSource(
@@ -358,6 +362,7 @@ describe('useMutableSource', () => {
358362
});
359363
});
360364

365+
// @gate enableUseMutableSource
361366
it('should unsubscribe and resubscribe if a new subscribe function is provided', () => {
362367
const source = createSource('a-one');
363368
const mutableSource = createMutableSource(source, param => param.version);
@@ -422,6 +427,7 @@ describe('useMutableSource', () => {
422427
});
423428
});
424429

430+
// @gate enableUseMutableSource
425431
it('should re-use previously read snapshot value when reading is unsafe', () => {
426432
const source = createSource('one');
427433
const mutableSource = createMutableSource(source, param => param.version);
@@ -484,6 +490,7 @@ describe('useMutableSource', () => {
484490
});
485491
});
486492

493+
// @gate enableUseMutableSource
487494
it('should read from source on newly mounted subtree if no pending updates are scheduled for source', () => {
488495
const source = createSource('one');
489496
const mutableSource = createMutableSource(source, param => param.version);
@@ -523,6 +530,7 @@ describe('useMutableSource', () => {
523530
});
524531
});
525532

533+
// @gate enableUseMutableSource
526534
it('should throw and restart render if source and snapshot are unavailable during an update', () => {
527535
const source = createSource('one');
528536
const mutableSource = createMutableSource(source, param => param.version);
@@ -586,6 +594,7 @@ describe('useMutableSource', () => {
586594
});
587595
});
588596

597+
// @gate enableUseMutableSource
589598
it('should throw and restart render if source and snapshot are unavailable during a sync update', () => {
590599
const source = createSource('one');
591600
const mutableSource = createMutableSource(source, param => param.version);
@@ -649,6 +658,7 @@ describe('useMutableSource', () => {
649658
});
650659
});
651660

661+
// @gate enableUseMutableSource
652662
it('should only update components whose subscriptions fire', () => {
653663
const source = createComplexSource('a:one', 'b:one');
654664
const mutableSource = createMutableSource(source, param => param.version);
@@ -687,6 +697,7 @@ describe('useMutableSource', () => {
687697
});
688698
});
689699

700+
// @gate enableUseMutableSource
690701
it('should detect tearing in part of the store not yet subscribed to', () => {
691702
const source = createComplexSource('a:one', 'b:one');
692703
const mutableSource = createMutableSource(source, param => param.version);
@@ -779,6 +790,7 @@ describe('useMutableSource', () => {
779790
});
780791
});
781792

793+
// @gate enableUseMutableSource
782794
it('does not schedule an update for subscriptions that fire with an unchanged snapshot', () => {
783795
const MockComponent = jest.fn(Component);
784796

@@ -805,6 +817,7 @@ describe('useMutableSource', () => {
805817
});
806818
});
807819

820+
// @gate enableUseMutableSource
808821
it('should throw and restart if getSnapshot changes between scheduled update and re-render', () => {
809822
const source = createSource('one');
810823
const mutableSource = createMutableSource(source, param => param.version);
@@ -845,6 +858,7 @@ describe('useMutableSource', () => {
845858
});
846859
});
847860

861+
// @gate enableUseMutableSource
848862
it('should recover from a mutation during yield when other work is scheduled', () => {
849863
const source = createSource('one');
850864
const mutableSource = createMutableSource(source, param => param.version);
@@ -899,6 +913,7 @@ describe('useMutableSource', () => {
899913
});
900914
});
901915

916+
// @gate enableUseMutableSource
902917
it('should not throw if the new getSnapshot returns the same snapshot value', () => {
903918
const source = createSource('one');
904919
const mutableSource = createMutableSource(source, param => param.version);
@@ -953,6 +968,7 @@ describe('useMutableSource', () => {
953968
});
954969
});
955970

971+
// @gate enableUseMutableSource
956972
it('should not throw if getSnapshot changes but the source can be safely read from anyway', () => {
957973
const source = createSource('one');
958974
const mutableSource = createMutableSource(source, param => param.version);
@@ -992,6 +1008,7 @@ describe('useMutableSource', () => {
9921008
});
9931009
});
9941010

1011+
// @gate enableUseMutableSource
9951012
it('should still schedule an update if an eager selector throws after a mutation', () => {
9961013
const source = createSource({
9971014
friends: [
@@ -1058,6 +1075,7 @@ describe('useMutableSource', () => {
10581075
});
10591076
});
10601077

1078+
// @gate enableUseMutableSource
10611079
it('should not warn about updates that fire between unmount and passive unsubscribe', () => {
10621080
const source = createSource('one');
10631081
const mutableSource = createMutableSource(source, param => param.version);
@@ -1094,6 +1112,7 @@ describe('useMutableSource', () => {
10941112
});
10951113
});
10961114

1115+
// @gate enableUseMutableSource
10971116
it('should support inline selectors and updates that are processed after selector change', async () => {
10981117
const source = createSource({
10991118
a: 'initial',
@@ -1138,6 +1157,7 @@ describe('useMutableSource', () => {
11381157
expect(root).toMatchRenderedOutput('Another update');
11391158
});
11401159

1160+
// @gate enableUseMutableSource
11411161
it('should clear the update queue when getSnapshot changes with pending lower priority updates', async () => {
11421162
const source = createSource({
11431163
a: 'initial',
@@ -1194,6 +1214,7 @@ describe('useMutableSource', () => {
11941214
expect(root).toMatchRenderedOutput('B: Update');
11951215
});
11961216

1217+
// @gate enableUseMutableSource
11971218
it('should clear the update queue when source changes with pending lower priority updates', async () => {
11981219
const sourceA = createSource('initial');
11991220
const sourceB = createSource('initial');
@@ -1238,6 +1259,7 @@ describe('useMutableSource', () => {
12381259
expect(root).toMatchRenderedOutput('B: Update');
12391260
});
12401261

1262+
// @gate enableUseMutableSource
12411263
it('should always treat reading as potentially unsafe when getSnapshot changes between renders', async () => {
12421264
const source = createSource({
12431265
a: 'foo',
@@ -1327,6 +1349,7 @@ describe('useMutableSource', () => {
13271349
expect(Scheduler).toHaveYielded(['x: bar, y: bar']);
13281350
});
13291351

1352+
// @gate enableUseMutableSource
13301353
it('getSnapshot changes and then source is mutated in between paint and passive effect phase', async () => {
13311354
const source = createSource({
13321355
a: 'foo',
@@ -1385,6 +1408,7 @@ describe('useMutableSource', () => {
13851408
expect(root).toMatchRenderedOutput('baz');
13861409
});
13871410

1411+
// @gate enableUseMutableSource
13881412
it('getSnapshot changes and then source is mutated in between paint and passive effect phase, case 2', async () => {
13891413
const source = createSource({
13901414
a: 'a0',
@@ -1455,6 +1479,7 @@ describe('useMutableSource', () => {
14551479
expect(root.getChildrenAsJSX()).toEqual('first: a1, second: a1');
14561480
});
14571481

1482+
// @gate enableUseMutableSource
14581483
it(
14591484
'if source is mutated after initial read but before subscription is set ' +
14601485
'up, should still entangle all pending mutations even if snapshot of ' +
@@ -1559,6 +1584,7 @@ describe('useMutableSource', () => {
15591584
},
15601585
);
15611586

1587+
// @gate enableUseMutableSource
15621588
it('warns about functions being used as snapshot values', async () => {
15631589
const source = createSource(() => 'a');
15641590
const mutableSource = createMutableSource(source, param => param.version);
@@ -1586,6 +1612,7 @@ describe('useMutableSource', () => {
15861612
expect(root).toMatchRenderedOutput('a');
15871613
});
15881614

1615+
// @gate enableUseMutableSource
15891616
it('getSnapshot changes and then source is mutated during interleaved event', async () => {
15901617
const {useEffect} = React;
15911618

@@ -1710,6 +1737,7 @@ describe('useMutableSource', () => {
17101737
});
17111738
});
17121739

1740+
// @gate enableUseMutableSource
17131741
it('should not tear with newly mounted component when updates were scheduled at a lower priority', async () => {
17141742
const source = createSource('one');
17151743
const mutableSource = createMutableSource(source, param => param.version);
@@ -1789,6 +1817,7 @@ describe('useMutableSource', () => {
17891817

17901818
if (__DEV__) {
17911819
describe('dev warnings', () => {
1820+
// @gate enableUseMutableSource
17921821
it('should warn if the subscribe function does not return an unsubscribe function', () => {
17931822
const source = createSource('one');
17941823
const mutableSource = createMutableSource(
@@ -1814,6 +1843,7 @@ describe('useMutableSource', () => {
18141843
);
18151844
});
18161845

1846+
// @gate enableUseMutableSource
18171847
it('should error if multiple renderers of the same type use a mutable source at the same time', () => {
18181848
const source = createSource('one');
18191849
const mutableSource = createMutableSource(
@@ -1894,6 +1924,7 @@ describe('useMutableSource', () => {
18941924
});
18951925
});
18961926

1927+
// @gate enableUseMutableSource
18971928
it('should error if multiple renderers of the same type use a mutable source at the same time with mutation between', () => {
18981929
const source = createSource('one');
18991930
const mutableSource = createMutableSource(

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

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ describe('useMutableSourceHydration', () => {
144144
return <div>{`${label}:${snapshot}`}</div>;
145145
}
146146

147+
// @gate enableUseMutableSource
147148
it('should render and hydrate', () => {
148149
const source = createSource('one');
149150
const mutableSource = createMutableSource(source, param => param.version);
@@ -180,6 +181,7 @@ describe('useMutableSourceHydration', () => {
180181
expect(source.listenerCount).toBe(1);
181182
});
182183

184+
// @gate enableUseMutableSource
183185
it('should detect a tear before hydrating a component', () => {
184186
const source = createSource('one');
185187
const mutableSource = createMutableSource(source, param => param.version);
@@ -224,6 +226,7 @@ describe('useMutableSourceHydration', () => {
224226
expect(source.listenerCount).toBe(1);
225227
});
226228

229+
// @gate enableUseMutableSource
227230
it('should detect a tear between hydrating components', () => {
228231
const source = createSource('one');
229232
const mutableSource = createMutableSource(source, param => param.version);
@@ -282,6 +285,7 @@ describe('useMutableSourceHydration', () => {
282285
expect(source.listenerCount).toBe(2);
283286
});
284287

288+
// @gate enableUseMutableSource
285289
it('should detect a tear between hydrating components reading from different parts of a source', () => {
286290
const source = createComplexSource('a:one', 'b:one');
287291
const mutableSource = createMutableSource(source, param => param.version);
@@ -371,6 +375,7 @@ describe('useMutableSourceHydration', () => {
371375
});
372376

373377
// @gate !enableSyncDefaultUpdates
378+
// @gate enableUseMutableSource
374379
it('should detect a tear during a higher priority interruption', () => {
375380
const source = createSource('one');
376381
const mutableSource = createMutableSource(source, param => param.version);

packages/react/index.experimental.js

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export {
4646
useInsertionEffect,
4747
useLayoutEffect,
4848
useMemo,
49-
useMutableSource as unstable_useMutableSource,
5049
useSyncExternalStore,
5150
useReducer,
5251
useRef,

packages/react/index.stable.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export {
3939
useInsertionEffect,
4040
useLayoutEffect,
4141
useMemo,
42-
useMutableSource as unstable_useMutableSource,
4342
useSyncExternalStore,
4443
useReducer,
4544
useRef,

0 commit comments

Comments
 (0)