Skip to content

Commit 4b17634

Browse files
noahlemenAndyPengc12
authored andcommitted
Remove useMutableSource (facebook#27011)
## Summary This PR cleans up `useMutableSource`. This has been blocked by a remaining dependency internally at Meta, but that has now been deleted. <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> ## How did you test this change? ``` yarn flow yarn lint yarn test --prod ``` <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. -->
1 parent d47c2b5 commit 4b17634

30 files changed

+4
-3023
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*/
99

1010
import type {
11-
MutableSource,
12-
MutableSourceGetSnapshotFn,
13-
MutableSourceSubscribeFn,
1411
ReactContext,
1512
ReactProviderType,
1613
StartTransitionOptions,
@@ -273,23 +270,6 @@ function useMemo<T>(
273270
return value;
274271
}
275272

276-
function useMutableSource<Source, Snapshot>(
277-
source: MutableSource<Source>,
278-
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
279-
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
280-
): Snapshot {
281-
// useMutableSource() composes multiple hooks internally.
282-
// Advance the current hook index the same number of times
283-
// so that subsequent hooks have the right memoized state.
284-
nextHook(); // MutableSource
285-
nextHook(); // State
286-
nextHook(); // Effect
287-
nextHook(); // Effect
288-
const value = getSnapshot(source._source);
289-
hookLog.push({primitive: 'MutableSource', stackError: new Error(), value});
290-
return value;
291-
}
292-
293273
function useSyncExternalStore<T>(
294274
subscribe: (() => void) => () => void,
295275
getSnapshot: () => T,
@@ -396,7 +376,6 @@ const Dispatcher: DispatcherType = {
396376
useRef,
397377
useState,
398378
useTransition,
399-
useMutableSource,
400379
useSyncExternalStore,
401380
useDeferredValue,
402381
useId,

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,52 +1036,6 @@ describe('ReactHooksInspectionIntegration', () => {
10361036
]);
10371037
});
10381038

1039-
// @gate enableUseMutableSource
1040-
it('should support composite useMutableSource hook', () => {
1041-
const createMutableSource =
1042-
React.createMutableSource || React.unstable_createMutableSource;
1043-
const useMutableSource =
1044-
React.useMutableSource || React.unstable_useMutableSource;
1045-
1046-
const mutableSource = createMutableSource({}, () => 1);
1047-
function Foo(props) {
1048-
useMutableSource(
1049-
mutableSource,
1050-
() => 'snapshot',
1051-
() => {},
1052-
);
1053-
React.useMemo(() => 'memo', []);
1054-
React.useMemo(() => 'not used', []);
1055-
return <div />;
1056-
}
1057-
const renderer = ReactTestRenderer.create(<Foo />);
1058-
const childFiber = renderer.root.findByType(Foo)._currentFiber();
1059-
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
1060-
expect(tree).toEqual([
1061-
{
1062-
id: 0,
1063-
isStateEditable: false,
1064-
name: 'MutableSource',
1065-
value: 'snapshot',
1066-
subHooks: [],
1067-
},
1068-
{
1069-
id: 1,
1070-
isStateEditable: false,
1071-
name: 'Memo',
1072-
value: 'memo',
1073-
subHooks: [],
1074-
},
1075-
{
1076-
id: 2,
1077-
isStateEditable: false,
1078-
name: 'Memo',
1079-
value: 'not used',
1080-
subHooks: [],
1081-
},
1082-
]);
1083-
});
1084-
10851039
it('should support composite useSyncExternalStore hook', () => {
10861040
const useSyncExternalStore = React.useSyncExternalStore;
10871041
function Foo() {

packages/react-dom/src/client/ReactDOMRoot.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {MutableSource, ReactNodeList} from 'shared/ReactTypes';
10+
import type {ReactNodeList} from 'shared/ReactTypes';
1111
import type {
1212
FiberRoot,
1313
TransitionTracingCallbacks,
@@ -47,7 +47,6 @@ export type CreateRootOptions = {
4747

4848
export type HydrateRootOptions = {
4949
// Hydration options
50-
hydratedSources?: Array<MutableSource<any>>,
5150
onHydrated?: (suspenseNode: Comment) => void,
5251
onDeleted?: (suspenseNode: Comment) => void,
5352
// Options for all roots
@@ -77,7 +76,6 @@ import {
7776
createHydrationContainer,
7877
updateContainer,
7978
findHostInstanceWithNoPortals,
80-
registerMutableSourceForHydration,
8179
flushSync,
8280
isAlreadyRendering,
8381
} from 'react-reconciler/src/ReactFiberReconciler';
@@ -298,8 +296,6 @@ export function hydrateRoot(
298296
// For now we reuse the whole bag of options since they contain
299297
// the hydration callbacks.
300298
const hydrationCallbacks = options != null ? options : null;
301-
// TODO: Delete this option
302-
const mutableSources = (options != null && options.hydratedSources) || null;
303299

304300
let isStrictMode = false;
305301
let concurrentUpdatesByDefaultOverride = false;
@@ -344,13 +340,6 @@ export function hydrateRoot(
344340
// This can't be a comment node since hydration doesn't work on comment nodes anyway.
345341
listenToAllSupportedEvents(container);
346342

347-
if (mutableSources) {
348-
for (let i = 0; i < mutableSources.length; i++) {
349-
const mutableSource = mutableSources[i];
350-
registerMutableSourceForHydration(root, mutableSource);
351-
}
352-
}
353-
354343
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
355344
return new ReactDOMHydrationRoot(root);
356345
}

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
ReactProviderType,
1212
ReactContext,
1313
ReactNodeList,
14-
MutableSource,
1514
} from 'shared/ReactTypes';
1615
import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy';
1716
import type {Fiber, FiberRoot} from './ReactInternalTypes';
@@ -106,7 +105,6 @@ import {
106105
enableTransitionTracing,
107106
enableLegacyHidden,
108107
enableCPUSuspense,
109-
enableUseMutableSource,
110108
enableFloat,
111109
enableHostSingletons,
112110
enableFormActions,
@@ -261,7 +259,6 @@ import {
261259
getWorkInProgressRoot,
262260
} from './ReactFiberWorkLoop';
263261
import {enqueueConcurrentRenderForLane} from './ReactFiberConcurrentUpdates';
264-
import {setWorkInProgressVersion} from './ReactMutableSource';
265262
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent';
266263
import {
267264
createCapturedValue,
@@ -1533,19 +1530,6 @@ function updateHostRoot(
15331530
} else {
15341531
// The outermost shell has not hydrated yet. Start hydrating.
15351532
enterHydrationState(workInProgress);
1536-
if (enableUseMutableSource) {
1537-
const mutableSourceEagerHydrationData =
1538-
root.mutableSourceEagerHydrationData;
1539-
if (mutableSourceEagerHydrationData != null) {
1540-
for (let i = 0; i < mutableSourceEagerHydrationData.length; i += 2) {
1541-
const mutableSource = ((mutableSourceEagerHydrationData[
1542-
i
1543-
]: any): MutableSource<any>);
1544-
const version = mutableSourceEagerHydrationData[i + 1];
1545-
setWorkInProgressVersion(mutableSource, version);
1546-
}
1547-
}
1548-
}
15491533

15501534
const child = mountChildFibers(
15511535
workInProgress,

packages/react-reconciler/src/ReactFiberCompleteWork.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ import {
4141
diffInCommitPhase,
4242
} from 'shared/ReactFeatureFlags';
4343

44-
import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource';
45-
4644
import {now} from './Scheduler';
4745

4846
import {
@@ -1038,7 +1036,6 @@ function completeWork(
10381036
popRootTransition(workInProgress, fiberRoot, renderLanes);
10391037
popHostContainer(workInProgress);
10401038
popTopLevelLegacyContextObject(workInProgress);
1041-
resetMutableSourceWorkInProgressVersions();
10421039
if (fiberRoot.pendingContext) {
10431040
fiberRoot.context = fiberRoot.pendingContext;
10441041
fiberRoot.pendingContext = null;

0 commit comments

Comments
 (0)