Skip to content

Commit 0ec711f

Browse files
committed
Delete useMutableSource implementation
This API was replaced by useSyncExternalStore
1 parent f50ff35 commit 0ec711f

37 files changed

+14
-3909
lines changed

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

+1-25
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
* @flow
88
*/
99

10-
import type {
11-
MutableSource,
12-
MutableSourceGetSnapshotFn,
13-
MutableSourceSubscribeFn,
14-
ReactContext,
15-
ReactProviderType,
16-
} from 'shared/ReactTypes';
10+
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
1711
import type {
1812
Fiber,
1913
Dispatcher as DispatcherType,
@@ -261,23 +255,6 @@ function useMemo<T>(
261255
return value;
262256
}
263257

264-
function useMutableSource<Source, Snapshot>(
265-
source: MutableSource<Source>,
266-
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
267-
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
268-
): Snapshot {
269-
// useMutableSource() composes multiple hooks internally.
270-
// Advance the current hook index the same number of times
271-
// so that subsequent hooks have the right memoized state.
272-
nextHook(); // MutableSource
273-
nextHook(); // State
274-
nextHook(); // Effect
275-
nextHook(); // Effect
276-
const value = getSnapshot(source._source);
277-
hookLog.push({primitive: 'MutableSource', stackError: new Error(), value});
278-
return value;
279-
}
280-
281258
function useSyncExternalStore<T>(
282259
subscribe: (() => void) => () => void,
283260
getSnapshot: () => T,
@@ -357,7 +334,6 @@ const Dispatcher: DispatcherType = {
357334
useRef,
358335
useState,
359336
useTransition,
360-
useMutableSource,
361337
useSyncExternalStore,
362338
useDeferredValue,
363339
useOpaqueIdentifier,

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

-37
Original file line numberDiff line numberDiff line change
@@ -1019,43 +1019,6 @@ describe('ReactHooksInspectionIntegration', () => {
10191019
]);
10201020
});
10211021

1022-
it('should support composite useMutableSource hook', () => {
1023-
const createMutableSource =
1024-
React.createMutableSource || React.unstable_createMutableSource;
1025-
const useMutableSource =
1026-
React.useMutableSource || React.unstable_useMutableSource;
1027-
1028-
const mutableSource = createMutableSource({}, () => 1);
1029-
function Foo(props) {
1030-
useMutableSource(
1031-
mutableSource,
1032-
() => 'snapshot',
1033-
() => {},
1034-
);
1035-
React.useMemo(() => 'memo', []);
1036-
return <div />;
1037-
}
1038-
const renderer = ReactTestRenderer.create(<Foo />);
1039-
const childFiber = renderer.root.findByType(Foo)._currentFiber();
1040-
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
1041-
expect(tree).toEqual([
1042-
{
1043-
id: 0,
1044-
isStateEditable: false,
1045-
name: 'MutableSource',
1046-
value: 'snapshot',
1047-
subHooks: [],
1048-
},
1049-
{
1050-
id: 1,
1051-
isStateEditable: false,
1052-
name: 'Memo',
1053-
value: 'memo',
1054-
subHooks: [],
1055-
},
1056-
]);
1057-
});
1058-
10591022
// @gate experimental || www
10601023
it('should support composite useSyncExternalStore hook', () => {
10611024
const useSyncExternalStore = React.unstable_useSyncExternalStore;

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

+1-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {Container} from './ReactDOMHostConfig';
11-
import type {MutableSource, ReactNodeList} from 'shared/ReactTypes';
11+
import type {ReactNodeList} from 'shared/ReactTypes';
1212
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1313

1414
export type RootType = {
@@ -24,7 +24,6 @@ export type CreateRootOptions = {
2424
hydrationOptions?: {
2525
onHydrated?: (suspenseNode: Comment) => void,
2626
onDeleted?: (suspenseNode: Comment) => void,
27-
mutableSources?: Array<MutableSource<any>>,
2827
...
2928
},
3029
// END OF TODO
@@ -35,7 +34,6 @@ export type CreateRootOptions = {
3534

3635
export type HydrateRootOptions = {
3736
// Hydration options
38-
hydratedSources?: Array<MutableSource<any>>,
3937
onHydrated?: (suspenseNode: Comment) => void,
4038
onDeleted?: (suspenseNode: Comment) => void,
4139
// Options for all roots
@@ -61,7 +59,6 @@ import {
6159
createContainer,
6260
updateContainer,
6361
findHostInstanceWithNoPortals,
64-
registerMutableSourceForHydration,
6562
} from 'react-reconciler/src/ReactFiberReconciler';
6663
import invariant from 'shared/invariant';
6764
import {ConcurrentRoot} from 'react-reconciler/src/ReactRootTags';
@@ -129,11 +126,6 @@ export function createRoot(
129126
const hydrate = options != null && options.hydrate === true;
130127
const hydrationCallbacks =
131128
(options != null && options.hydrationOptions) || null;
132-
const mutableSources =
133-
(options != null &&
134-
options.hydrationOptions != null &&
135-
options.hydrationOptions.mutableSources) ||
136-
null;
137129
// END TODO
138130

139131
const isStrictMode = options != null && options.unstable_strictMode === true;
@@ -159,15 +151,6 @@ export function createRoot(
159151
container.nodeType === COMMENT_NODE ? container.parentNode : container;
160152
listenToAllSupportedEvents(rootContainerElement);
161153

162-
// TODO: Delete this path
163-
if (mutableSources) {
164-
for (let i = 0; i < mutableSources.length; i++) {
165-
const mutableSource = mutableSources[i];
166-
registerMutableSourceForHydration(root, mutableSource);
167-
}
168-
}
169-
// END TODO
170-
171154
return new ReactDOMRoot(root);
172155
}
173156

@@ -185,7 +168,6 @@ export function hydrateRoot(
185168
// For now we reuse the whole bag of options since they contain
186169
// the hydration callbacks.
187170
const hydrationCallbacks = options != null ? options : null;
188-
const mutableSources = (options != null && options.hydratedSources) || null;
189171
const isStrictMode = options != null && options.unstable_strictMode === true;
190172

191173
let concurrentUpdatesByDefaultOverride = null;
@@ -208,13 +190,6 @@ export function hydrateRoot(
208190
// This can't be a comment node since hydration doesn't work on comment nodes anyway.
209191
listenToAllSupportedEvents(container);
210192

211-
if (mutableSources) {
212-
for (let i = 0; i < mutableSources.length; i++) {
213-
const mutableSource = mutableSources[i];
214-
registerMutableSourceForHydration(root, mutableSource);
215-
}
216-
}
217-
218193
// Render the initial children
219194
updateContainer(initialChildren, root, null, null);
220195

packages/react-dom/src/server/ReactPartialRendererHooks.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99

1010
import type {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactInternalTypes';
1111

12-
import type {
13-
MutableSource,
14-
MutableSourceGetSnapshotFn,
15-
MutableSourceSubscribeFn,
16-
ReactContext,
17-
} from 'shared/ReactTypes';
12+
import type {ReactContext} from 'shared/ReactTypes';
1813
import type PartialRenderer from './ReactPartialRenderer';
1914

2015
import {validateContextBounds} from './ReactPartialRendererContext';
@@ -466,18 +461,6 @@ export function useCallback<T>(
466461
return useMemo(() => callback, deps);
467462
}
468463

469-
// TODO Decide on how to implement this hook for server rendering.
470-
// If a mutation occurs during render, consider triggering a Suspense boundary
471-
// and falling back to client rendering.
472-
function useMutableSource<Source, Snapshot>(
473-
source: MutableSource<Source>,
474-
getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
475-
subscribe: MutableSourceSubscribeFn<Source, Snapshot>,
476-
): Snapshot {
477-
resolveCurrentlyRenderingComponent();
478-
return getSnapshot(source._source);
479-
}
480-
481464
function useSyncExternalStore<T>(
482465
subscribe: (() => void) => () => void,
483466
getSnapshot: () => T,
@@ -536,8 +519,6 @@ export const Dispatcher: DispatcherType = {
536519
useDeferredValue,
537520
useTransition,
538521
useOpaqueIdentifier,
539-
// Subscriptions are not setup in a server environment.
540-
useMutableSource,
541522
useSyncExternalStore,
542523
};
543524

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

-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy';
1212
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {TypeOfMode} from './ReactTypeOfMode';
1414
import type {Lanes, Lane} from './ReactFiberLane.new';
15-
import type {MutableSource} from 'shared/ReactTypes';
1615
import type {
1716
SuspenseState,
1817
SuspenseListRenderState,
@@ -145,7 +144,6 @@ import {
145144
isSuspenseInstancePending,
146145
isSuspenseInstanceFallback,
147146
registerSuspenseInstanceRetry,
148-
supportsHydration,
149147
isPrimaryRenderer,
150148
supportsPersistence,
151149
getOffscreenContainerProps,
@@ -224,7 +222,6 @@ import {
224222
RetryAfterError,
225223
NoContext,
226224
} from './ReactFiberWorkLoop.new';
227-
import {setWorkInProgressVersion} from './ReactMutableSource.new';
228225
import {
229226
requestCacheFromPool,
230227
pushCacheProvider,
@@ -1303,21 +1300,6 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13031300
// We always try to hydrate. If this isn't a hydration pass there won't
13041301
// be any children to hydrate which is effectively the same thing as
13051302
// not hydrating.
1306-
1307-
if (supportsHydration) {
1308-
const mutableSourceEagerHydrationData =
1309-
root.mutableSourceEagerHydrationData;
1310-
if (mutableSourceEagerHydrationData != null) {
1311-
for (let i = 0; i < mutableSourceEagerHydrationData.length; i += 2) {
1312-
const mutableSource = ((mutableSourceEagerHydrationData[
1313-
i
1314-
]: any): MutableSource<any>);
1315-
const version = mutableSourceEagerHydrationData[i + 1];
1316-
setWorkInProgressVersion(mutableSource, version);
1317-
}
1318-
}
1319-
}
1320-
13211303
const child = mountChildFibers(
13221304
workInProgress,
13231305
null,

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

-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy';
1212
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {TypeOfMode} from './ReactTypeOfMode';
1414
import type {Lanes, Lane} from './ReactFiberLane.old';
15-
import type {MutableSource} from 'shared/ReactTypes';
1615
import type {
1716
SuspenseState,
1817
SuspenseListRenderState,
@@ -145,7 +144,6 @@ import {
145144
isSuspenseInstancePending,
146145
isSuspenseInstanceFallback,
147146
registerSuspenseInstanceRetry,
148-
supportsHydration,
149147
isPrimaryRenderer,
150148
supportsPersistence,
151149
getOffscreenContainerProps,
@@ -224,7 +222,6 @@ import {
224222
RetryAfterError,
225223
NoContext,
226224
} from './ReactFiberWorkLoop.old';
227-
import {setWorkInProgressVersion} from './ReactMutableSource.old';
228225
import {
229226
requestCacheFromPool,
230227
pushCacheProvider,
@@ -1303,21 +1300,6 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13031300
// We always try to hydrate. If this isn't a hydration pass there won't
13041301
// be any children to hydrate which is effectively the same thing as
13051302
// not hydrating.
1306-
1307-
if (supportsHydration) {
1308-
const mutableSourceEagerHydrationData =
1309-
root.mutableSourceEagerHydrationData;
1310-
if (mutableSourceEagerHydrationData != null) {
1311-
for (let i = 0; i < mutableSourceEagerHydrationData.length; i += 2) {
1312-
const mutableSource = ((mutableSourceEagerHydrationData[
1313-
i
1314-
]: any): MutableSource<any>);
1315-
const version = mutableSourceEagerHydrationData[i + 1];
1316-
setWorkInProgressVersion(mutableSource, version);
1317-
}
1318-
}
1319-
}
1320-
13211303
const child = mountChildFibers(
13221304
workInProgress,
13231305
null,

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

-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.new';
3030
import type {OffscreenState} from './ReactFiberOffscreenComponent';
3131
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new';
3232

33-
import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.new';
34-
3533
import {now} from './Scheduler';
3634

3735
import {
@@ -854,7 +852,6 @@ function completeWork(
854852
}
855853
popHostContainer(workInProgress);
856854
popTopLevelLegacyContextObject(workInProgress);
857-
resetMutableSourceWorkInProgressVersions();
858855
if (fiberRoot.pendingContext) {
859856
fiberRoot.context = fiberRoot.pendingContext;
860857
fiberRoot.pendingContext = null;

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

-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.old';
3030
import type {OffscreenState} from './ReactFiberOffscreenComponent';
3131
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
3232

33-
import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.old';
34-
3533
import {now} from './Scheduler';
3634

3735
import {
@@ -854,7 +852,6 @@ function completeWork(
854852
}
855853
popHostContainer(workInProgress);
856854
popTopLevelLegacyContextObject(workInProgress);
857-
resetMutableSourceWorkInProgressVersions();
858855
if (fiberRoot.pendingContext) {
859856
fiberRoot.context = fiberRoot.pendingContext;
860857
fiberRoot.pendingContext = null;

0 commit comments

Comments
 (0)