GeezerVison is showing github.com — Delete useMutableSource implementation (#22292) · react/react@8209de2
File treeExpand file treeCollapse file tree Open diff view settings react-suspense-test-utils/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/ReactDebugHooks.js +1-25Lines changed: 1 addition & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 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'; | 17 | 11 | import type { | 18 | 12 | Fiber, | 19 | 13 | Dispatcher as DispatcherType, | @@ -261,23 +255,6 @@ function useMemo<T>( | 261 | 255 | return value; | 262 | 256 | } | 263 | 257 |
| 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 | | - | 281 | 258 | function useSyncExternalStore<T>( | 282 | 259 | subscribe: (() => void) => () => void, | 283 | 260 | getSnapshot: () => T, | @@ -357,7 +334,6 @@ const Dispatcher: DispatcherType = { | 357 | 334 | useRef, | 358 | 335 | useState, | 359 | 336 | useTransition, | 360 | | - useMutableSource, | 361 | 337 | useSyncExternalStore, | 362 | 338 | useDeferredValue, | 363 | 339 | useOpaqueIdentifier, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js -37Lines changed: 0 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1019,43 +1019,6 @@ describe('ReactHooksInspectionIntegration', () => { | 1019 | 1019 | ]); | 1020 | 1020 | }); | 1021 | 1021 |
| 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 | | - | 1059 | 1022 | // @gate experimental || www | 1060 | 1023 | it('should support composite useSyncExternalStore hook', () => { | 1061 | 1024 | const useSyncExternalStore = React.unstable_useSyncExternalStore; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMRoot.js +1-26Lines changed: 1 addition & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | */ | 9 | 9 |
| 10 | 10 | import type {Container} from './ReactDOMHostConfig'; | 11 | | -import type {MutableSource, ReactNodeList} from 'shared/ReactTypes'; | | 11 | +import type {ReactNodeList} from 'shared/ReactTypes'; | 12 | 12 | import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; | 13 | 13 |
| 14 | 14 | export type RootType = { | @@ -24,7 +24,6 @@ export type CreateRootOptions = { | 24 | 24 | hydrationOptions?: { | 25 | 25 | onHydrated?: (suspenseNode: Comment) => void, | 26 | 26 | onDeleted?: (suspenseNode: Comment) => void, | 27 | | - mutableSources?: Array<MutableSource<any>>, | 28 | 27 | ... | 29 | 28 | }, | 30 | 29 | // END OF TODO | @@ -35,7 +34,6 @@ export type CreateRootOptions = { | 35 | 34 |
| 36 | 35 | export type HydrateRootOptions = { | 37 | 36 | // Hydration options | 38 | | - hydratedSources?: Array<MutableSource<any>>, | 39 | 37 | onHydrated?: (suspenseNode: Comment) => void, | 40 | 38 | onDeleted?: (suspenseNode: Comment) => void, | 41 | 39 | // Options for all roots | @@ -61,7 +59,6 @@ import { | 61 | 59 | createContainer, | 62 | 60 | updateContainer, | 63 | 61 | findHostInstanceWithNoPortals, | 64 | | - registerMutableSourceForHydration, | 65 | 62 | } from 'react-reconciler/src/ReactFiberReconciler'; | 66 | 63 | import invariant from 'shared/invariant'; | 67 | 64 | import {ConcurrentRoot} from 'react-reconciler/src/ReactRootTags'; | @@ -129,11 +126,6 @@ export function createRoot( | 129 | 126 | const hydrate = options != null && options.hydrate === true; | 130 | 127 | const hydrationCallbacks = | 131 | 128 | (options != null && options.hydrationOptions) || null; | 132 | | - const mutableSources = | 133 | | - (options != null && | 134 | | - options.hydrationOptions != null && | 135 | | - options.hydrationOptions.mutableSources) || | 136 | | - null; | 137 | 129 | // END TODO | 138 | 130 |
| 139 | 131 | const isStrictMode = options != null && options.unstable_strictMode === true; | @@ -159,15 +151,6 @@ export function createRoot( | 159 | 151 | container.nodeType === COMMENT_NODE ? container.parentNode : container; | 160 | 152 | listenToAllSupportedEvents(rootContainerElement); | 161 | 153 |
| 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 | | - | 171 | 154 | return new ReactDOMRoot(root); | 172 | 155 | } | 173 | 156 |
| @@ -185,7 +168,6 @@ export function hydrateRoot( | 185 | 168 | // For now we reuse the whole bag of options since they contain | 186 | 169 | // the hydration callbacks. | 187 | 170 | const hydrationCallbacks = options != null ? options : null; | 188 | | - const mutableSources = (options != null && options.hydratedSources) || null; | 189 | 171 | const isStrictMode = options != null && options.unstable_strictMode === true; | 190 | 172 |
| 191 | 173 | let concurrentUpdatesByDefaultOverride = null; | @@ -208,13 +190,6 @@ export function hydrateRoot( | 208 | 190 | // This can't be a comment node since hydration doesn't work on comment nodes anyway. | 209 | 191 | listenToAllSupportedEvents(container); | 210 | 192 |
| 211 | | - if (mutableSources) { | 212 | | - for (let i = 0; i < mutableSources.length; i++) { | 213 | | - const mutableSource = mutableSources[i]; | 214 | | - registerMutableSourceForHydration(root, mutableSource); | 215 | | - } | 216 | | - } | 217 | | - | 218 | 193 | // Render the initial children | 219 | 194 | updateContainer(initialChildren, root, null, null); | 220 | 195 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactPartialRendererHooks.js +1-20Lines changed: 1 addition & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import type {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactInternalTypes'; | 11 | 11 |
| 12 | | -import type { | 13 | | - MutableSource, | 14 | | - MutableSourceGetSnapshotFn, | 15 | | - MutableSourceSubscribeFn, | 16 | | - ReactContext, | 17 | | -} from 'shared/ReactTypes'; | | 12 | +import type {ReactContext} from 'shared/ReactTypes'; | 18 | 13 | import type PartialRenderer from './ReactPartialRenderer'; | 19 | 14 |
| 20 | 15 | import {validateContextBounds} from './ReactPartialRendererContext'; | @@ -466,18 +461,6 @@ export function useCallback<T>( | 466 | 461 | return useMemo(() => callback, deps); | 467 | 462 | } | 468 | 463 |
| 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 | | - | 481 | 464 | function useSyncExternalStore<T>( | 482 | 465 | subscribe: (() => void) => () => void, | 483 | 466 | getSnapshot: () => T, | @@ -536,8 +519,6 @@ export const Dispatcher: DispatcherType = { | 536 | 519 | useDeferredValue, | 537 | 520 | useTransition, | 538 | 521 | useOpaqueIdentifier, | 539 | | - // Subscriptions are not setup in a server environment. | 540 | | - useMutableSource, | 541 | 522 | useSyncExternalStore, | 542 | 523 | }; | 543 | 524 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js -18Lines changed: 0 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,6 @@ import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy'; | 12 | 12 | import type {Fiber, FiberRoot} from './ReactInternalTypes'; | 13 | 13 | import type {TypeOfMode} from './ReactTypeOfMode'; | 14 | 14 | import type {Lanes, Lane} from './ReactFiberLane.new'; | 15 | | -import type {MutableSource} from 'shared/ReactTypes'; | 16 | 15 | import type { | 17 | 16 | SuspenseState, | 18 | 17 | SuspenseListRenderState, | @@ -145,7 +144,6 @@ import { | 145 | 144 | isSuspenseInstancePending, | 146 | 145 | isSuspenseInstanceFallback, | 147 | 146 | registerSuspenseInstanceRetry, | 148 | | - supportsHydration, | 149 | 147 | isPrimaryRenderer, | 150 | 148 | supportsPersistence, | 151 | 149 | getOffscreenContainerProps, | @@ -224,7 +222,6 @@ import { | 224 | 222 | RetryAfterError, | 225 | 223 | NoContext, | 226 | 224 | } from './ReactFiberWorkLoop.new'; | 227 | | -import {setWorkInProgressVersion} from './ReactMutableSource.new'; | 228 | 225 | import { | 229 | 226 | requestCacheFromPool, | 230 | 227 | pushCacheProvider, | @@ -1303,21 +1300,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1303 | 1300 | // We always try to hydrate. If this isn't a hydration pass there won't | 1304 | 1301 | // be any children to hydrate which is effectively the same thing as | 1305 | 1302 | // 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 | | - | 1321 | 1303 | const child = mountChildFibers( | 1322 | 1304 | workInProgress, | 1323 | 1305 | null, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js -18Lines changed: 0 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,6 @@ import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy'; | 12 | 12 | import type {Fiber, FiberRoot} from './ReactInternalTypes'; | 13 | 13 | import type {TypeOfMode} from './ReactTypeOfMode'; | 14 | 14 | import type {Lanes, Lane} from './ReactFiberLane.old'; | 15 | | -import type {MutableSource} from 'shared/ReactTypes'; | 16 | 15 | import type { | 17 | 16 | SuspenseState, | 18 | 17 | SuspenseListRenderState, | @@ -145,7 +144,6 @@ import { | 145 | 144 | isSuspenseInstancePending, | 146 | 145 | isSuspenseInstanceFallback, | 147 | 146 | registerSuspenseInstanceRetry, | 148 | | - supportsHydration, | 149 | 147 | isPrimaryRenderer, | 150 | 148 | supportsPersistence, | 151 | 149 | getOffscreenContainerProps, | @@ -224,7 +222,6 @@ import { | 224 | 222 | RetryAfterError, | 225 | 223 | NoContext, | 226 | 224 | } from './ReactFiberWorkLoop.old'; | 227 | | -import {setWorkInProgressVersion} from './ReactMutableSource.old'; | 228 | 225 | import { | 229 | 226 | requestCacheFromPool, | 230 | 227 | pushCacheProvider, | @@ -1303,21 +1300,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1303 | 1300 | // We always try to hydrate. If this isn't a hydration pass there won't | 1304 | 1301 | // be any children to hydrate which is effectively the same thing as | 1305 | 1302 | // 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 | | - | 1321 | 1303 | const child = mountChildFibers( | 1322 | 1304 | workInProgress, | 1323 | 1305 | null, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.new.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,8 +30,6 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.new'; | 30 | 30 | import type {OffscreenState} from './ReactFiberOffscreenComponent'; | 31 | 31 | import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new'; | 32 | 32 |
| 33 | | -import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.new'; | 34 | | - | 35 | 33 | import {now} from './Scheduler'; | 36 | 34 |
| 37 | 35 | import { | @@ -854,7 +852,6 @@ function completeWork( | 854 | 852 | } | 855 | 853 | popHostContainer(workInProgress); | 856 | 854 | popTopLevelLegacyContextObject(workInProgress); | 857 | | - resetMutableSourceWorkInProgressVersions(); | 858 | 855 | if (fiberRoot.pendingContext) { | 859 | 856 | fiberRoot.context = fiberRoot.pendingContext; | 860 | 857 | fiberRoot.pendingContext = null; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.old.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,8 +30,6 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.old'; | 30 | 30 | import type {OffscreenState} from './ReactFiberOffscreenComponent'; | 31 | 31 | import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old'; | 32 | 32 |
| 33 | | -import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.old'; | 34 | | - | 35 | 33 | import {now} from './Scheduler'; | 36 | 34 |
| 37 | 35 | import { | @@ -854,7 +852,6 @@ function completeWork( | 854 | 852 | } | 855 | 853 | popHostContainer(workInProgress); | 856 | 854 | popTopLevelLegacyContextObject(workInProgress); | 857 | | - resetMutableSourceWorkInProgressVersions(); | 858 | 855 | if (fiberRoot.pendingContext) { | 859 | 856 | fiberRoot.context = fiberRoot.pendingContext; | 860 | 857 | fiberRoot.pendingContext = null; | |
|