From a8c16a00406a204f0153c21023a04ca9a68411da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 12 Oct 2022 23:13:39 -0400 Subject: [PATCH] Split Cache into its own Dispatcher (#25474) * Missing Hooks * Remove www forks. These can use __SECRET... instead. * Move cache to separate dispatcher These will be available in more contexts than just render. --- .../react-debug-tools/src/ReactDebugHooks.js | 5 -- .../src/ReactFiberCache.new.js | 41 +++++++++++++++++ .../src/ReactFiberCache.old.js | 41 +++++++++++++++++ .../src/ReactFiberHooks.new.js | 46 +------------------ .../src/ReactFiberHooks.old.js | 46 +------------------ .../src/ReactFiberWorkLoop.new.js | 22 +++++++++ .../src/ReactFiberWorkLoop.old.js | 22 +++++++++ .../src/ReactInternalTypes.js | 7 ++- packages/react-server/src/ReactFizzCache.js | 23 ++++++++++ packages/react-server/src/ReactFizzHooks.js | 19 +++----- packages/react-server/src/ReactFizzServer.js | 18 ++++++-- packages/react-server/src/ReactFlightCache.js | 43 +++++++++++++++++ packages/react-server/src/ReactFlightHooks.js | 41 +++-------------- .../react-server/src/ReactFlightServer.js | 15 ++++-- .../src/ReactSuspenseTestUtils.js | 32 +++---------- packages/react/src/ReactCurrentCache.js | 19 ++++++++ packages/react/src/ReactCurrentDispatcher.js | 4 -- packages/react/src/ReactHooks.js | 27 +++++++++-- packages/react/src/ReactSharedInternals.js | 2 + .../src/forks/ReactCurrentDispatcher.www.js | 8 ---- .../react/src/forks/ReactCurrentOwner.www.js | 8 ---- .../src/forks/ReactSharedInternals.umd.js | 2 + scripts/error-codes/codes.json | 5 +- scripts/rollup/forks.js | 26 ----------- 24 files changed, 293 insertions(+), 229 deletions(-) create mode 100644 packages/react-reconciler/src/ReactFiberCache.new.js create mode 100644 packages/react-reconciler/src/ReactFiberCache.old.js create mode 100644 packages/react-server/src/ReactFizzCache.js create mode 100644 packages/react-server/src/ReactFlightCache.js create mode 100644 packages/react/src/ReactCurrentCache.js delete mode 100644 packages/react/src/forks/ReactCurrentDispatcher.www.js delete mode 100644 packages/react/src/forks/ReactCurrentOwner.www.js diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index 2bd458d06757d..74ca5568f1804 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -101,10 +101,6 @@ function nextHook(): null | Hook { return hook; } -function getCacheForType(resourceType: () => T): T { - throw new Error('Not implemented.'); -} - function readContext(context: ReactContext): T { // For now we don't expose readContext usage in the hooks debugging info. return context._currentValue; @@ -331,7 +327,6 @@ function useId(): string { } const Dispatcher: DispatcherType = { - getCacheForType, readContext, useCacheRefresh, useCallback, diff --git a/packages/react-reconciler/src/ReactFiberCache.new.js b/packages/react-reconciler/src/ReactFiberCache.new.js new file mode 100644 index 0000000000000..c0ee28b855034 --- /dev/null +++ b/packages/react-reconciler/src/ReactFiberCache.new.js @@ -0,0 +1,41 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {CacheDispatcher} from './ReactInternalTypes'; +import type {Cache} from './ReactFiberCacheComponent.new'; + +import {enableCache} from 'shared/ReactFeatureFlags'; +import {readContext} from './ReactFiberNewContext.new'; +import {CacheContext} from './ReactFiberCacheComponent.new'; + +function getCacheSignal(): AbortSignal { + if (!enableCache) { + throw new Error('Not implemented.'); + } + const cache: Cache = readContext(CacheContext); + return cache.controller.signal; +} + +function getCacheForType(resourceType: () => T): T { + if (!enableCache) { + throw new Error('Not implemented.'); + } + const cache: Cache = readContext(CacheContext); + let cacheForType: T | void = (cache.data.get(resourceType): any); + if (cacheForType === undefined) { + cacheForType = resourceType(); + cache.data.set(resourceType, cacheForType); + } + return cacheForType; +} + +export const DefaultCacheDispatcher: CacheDispatcher = { + getCacheSignal, + getCacheForType, +}; diff --git a/packages/react-reconciler/src/ReactFiberCache.old.js b/packages/react-reconciler/src/ReactFiberCache.old.js new file mode 100644 index 0000000000000..507fccbc939fb --- /dev/null +++ b/packages/react-reconciler/src/ReactFiberCache.old.js @@ -0,0 +1,41 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {CacheDispatcher} from './ReactInternalTypes'; +import type {Cache} from './ReactFiberCacheComponent.old'; + +import {enableCache} from 'shared/ReactFeatureFlags'; +import {readContext} from './ReactFiberNewContext.old'; +import {CacheContext} from './ReactFiberCacheComponent.old'; + +function getCacheSignal(): AbortSignal { + if (!enableCache) { + throw new Error('Not implemented.'); + } + const cache: Cache = readContext(CacheContext); + return cache.controller.signal; +} + +function getCacheForType(resourceType: () => T): T { + if (!enableCache) { + throw new Error('Not implemented.'); + } + const cache: Cache = readContext(CacheContext); + let cacheForType: T | void = (cache.data.get(resourceType): any); + if (cacheForType === undefined) { + cacheForType = resourceType(); + cache.data.set(resourceType, cacheForType); + } + return cacheForType; +} + +export const DefaultCacheDispatcher: CacheDispatcher = { + getCacheSignal, + getCacheForType, +}; diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index f430a4cad6baf..2f854410afb11 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -26,7 +26,6 @@ import type { import type {Lanes, Lane} from './ReactFiberLane.new'; import type {HookFlags} from './ReactHookEffectTags'; import type {FiberRoot} from './ReactInternalTypes'; -import type {Cache} from './ReactFiberCacheComponent.new'; import type {Flags} from './ReactFiberFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; @@ -122,7 +121,7 @@ import { } from './ReactMutableSource.new'; import {logStateUpdateScheduled} from './DebugTracing'; import {markStateUpdateScheduled} from './ReactFiberDevToolsHook.new'; -import {createCache, CacheContext} from './ReactFiberCacheComponent.new'; +import {createCache} from './ReactFiberCacheComponent.new'; import { createUpdate as createLegacyQueueUpdate, enqueueUpdate as enqueueLegacyQueueUpdate, @@ -2600,27 +2599,6 @@ function markUpdateInDevTools(fiber, lane, action: A) { } } -function getCacheSignal(): AbortSignal { - if (!enableCache) { - throw new Error('Not implemented.'); - } - const cache: Cache = readContext(CacheContext); - return cache.controller.signal; -} - -function getCacheForType(resourceType: () => T): T { - if (!enableCache) { - throw new Error('Not implemented.'); - } - const cache: Cache = readContext(CacheContext); - let cacheForType: T | void = (cache.data.get(resourceType): any); - if (cacheForType === undefined) { - cacheForType = resourceType(); - cache.data.set(resourceType, cacheForType); - } - return cacheForType; -} - export const ContextOnlyDispatcher: Dispatcher = { readContext, @@ -2644,8 +2622,6 @@ export const ContextOnlyDispatcher: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (ContextOnlyDispatcher: Dispatcher).getCacheSignal = getCacheSignal; - (ContextOnlyDispatcher: Dispatcher).getCacheForType = getCacheForType; (ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError; } if (enableUseHook) { @@ -2681,8 +2657,6 @@ const HooksDispatcherOnMount: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType; // $FlowFixMe[escaped-generic] discovered when updating Flow (HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh; } @@ -2718,8 +2692,6 @@ const HooksDispatcherOnUpdate: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnUpdate: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnUpdate: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnUpdate: Dispatcher).useCacheRefresh = updateRefresh; } if (enableUseMemoCacheHook) { @@ -2755,8 +2727,6 @@ const HooksDispatcherOnRerender: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnRerender: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnRerender: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh; } if (enableUseHook) { @@ -2935,8 +2905,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMountInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMountInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; mountHookTypesDev(); @@ -3094,8 +3062,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3253,8 +3219,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnUpdateInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnUpdateInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3413,8 +3377,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnRerenderInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnRerenderInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3589,8 +3551,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; mountHookTypesDev(); @@ -3776,8 +3736,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3964,8 +3922,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index d5add2ffec5c4..bbdb1e2478f99 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -26,7 +26,6 @@ import type { import type {Lanes, Lane} from './ReactFiberLane.old'; import type {HookFlags} from './ReactHookEffectTags'; import type {FiberRoot} from './ReactInternalTypes'; -import type {Cache} from './ReactFiberCacheComponent.old'; import type {Flags} from './ReactFiberFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; @@ -122,7 +121,7 @@ import { } from './ReactMutableSource.old'; import {logStateUpdateScheduled} from './DebugTracing'; import {markStateUpdateScheduled} from './ReactFiberDevToolsHook.old'; -import {createCache, CacheContext} from './ReactFiberCacheComponent.old'; +import {createCache} from './ReactFiberCacheComponent.old'; import { createUpdate as createLegacyQueueUpdate, enqueueUpdate as enqueueLegacyQueueUpdate, @@ -2600,27 +2599,6 @@ function markUpdateInDevTools(fiber, lane, action: A) { } } -function getCacheSignal(): AbortSignal { - if (!enableCache) { - throw new Error('Not implemented.'); - } - const cache: Cache = readContext(CacheContext); - return cache.controller.signal; -} - -function getCacheForType(resourceType: () => T): T { - if (!enableCache) { - throw new Error('Not implemented.'); - } - const cache: Cache = readContext(CacheContext); - let cacheForType: T | void = (cache.data.get(resourceType): any); - if (cacheForType === undefined) { - cacheForType = resourceType(); - cache.data.set(resourceType, cacheForType); - } - return cacheForType; -} - export const ContextOnlyDispatcher: Dispatcher = { readContext, @@ -2644,8 +2622,6 @@ export const ContextOnlyDispatcher: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (ContextOnlyDispatcher: Dispatcher).getCacheSignal = getCacheSignal; - (ContextOnlyDispatcher: Dispatcher).getCacheForType = getCacheForType; (ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError; } if (enableUseHook) { @@ -2681,8 +2657,6 @@ const HooksDispatcherOnMount: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType; // $FlowFixMe[escaped-generic] discovered when updating Flow (HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh; } @@ -2718,8 +2692,6 @@ const HooksDispatcherOnUpdate: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnUpdate: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnUpdate: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnUpdate: Dispatcher).useCacheRefresh = updateRefresh; } if (enableUseMemoCacheHook) { @@ -2755,8 +2727,6 @@ const HooksDispatcherOnRerender: Dispatcher = { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnRerender: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnRerender: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh; } if (enableUseHook) { @@ -2935,8 +2905,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMountInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMountInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; mountHookTypesDev(); @@ -3094,8 +3062,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3253,8 +3219,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnUpdateInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnUpdateInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3413,8 +3377,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (HooksDispatcherOnRerenderInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (HooksDispatcherOnRerenderInDEV: Dispatcher).getCacheForType = getCacheForType; (HooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3589,8 +3551,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; mountHookTypesDev(); @@ -3776,8 +3736,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); @@ -3964,8 +3922,6 @@ if (__DEV__) { unstable_isNewReconciler: enableNewReconciler, }; if (enableCache) { - (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).getCacheSignal = getCacheSignal; - (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).getCacheForType = getCacheForType; (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh = function useCacheRefresh() { currentHookNameInDev = 'useCacheRefresh'; updateHookTypesDev(); diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index ff1f2d02364a1..38994cdef5291 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -207,6 +207,7 @@ import { ContextOnlyDispatcher, getIsUpdatingOpaqueValueInRenderPhaseInDEV, } from './ReactFiberHooks.new'; +import {DefaultCacheDispatcher} from './ReactFiberCache.new'; import { createCapturedValueAtFiber, type CapturedValue, @@ -279,6 +280,7 @@ const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; const { ReactCurrentDispatcher, + ReactCurrentCache, ReactCurrentOwner, ReactCurrentBatchConfig, ReactCurrentActQueue, @@ -1790,6 +1792,22 @@ function popDispatcher(prevDispatcher) { ReactCurrentDispatcher.current = prevDispatcher; } +function pushCacheDispatcher() { + if (enableCache) { + const prevCacheDispatcher = ReactCurrentCache.current; + ReactCurrentCache.current = DefaultCacheDispatcher; + return prevCacheDispatcher; + } else { + return null; + } +} + +function popCacheDispatcher(prevCacheDispatcher) { + if (enableCache) { + ReactCurrentCache.current = prevCacheDispatcher; + } +} + export function markCommitTimeOfFallback() { globalMostRecentFallbackTime = now(); } @@ -1857,6 +1875,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) { const prevExecutionContext = executionContext; executionContext |= RenderContext; const prevDispatcher = pushDispatcher(root.containerInfo); + const prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack // and prepare a fresh one. Otherwise we'll continue where we left off. @@ -1903,6 +1922,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) { executionContext = prevExecutionContext; popDispatcher(prevDispatcher); + popCacheDispatcher(prevCacheDispatcher); if (workInProgress !== null) { // This is a sync render, so we should have finished the whole tree. @@ -1957,6 +1977,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) { const prevExecutionContext = executionContext; executionContext |= RenderContext; const prevDispatcher = pushDispatcher(root.containerInfo); + const prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack // and prepare a fresh one. Otherwise we'll continue where we left off. @@ -2009,6 +2030,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) { resetContextDependencies(); popDispatcher(prevDispatcher); + popCacheDispatcher(prevCacheDispatcher); executionContext = prevExecutionContext; if (__DEV__) { diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 9f9c70ff2c0dd..1dacb1fd5685e 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -207,6 +207,7 @@ import { ContextOnlyDispatcher, getIsUpdatingOpaqueValueInRenderPhaseInDEV, } from './ReactFiberHooks.old'; +import {DefaultCacheDispatcher} from './ReactFiberCache.old'; import { createCapturedValueAtFiber, type CapturedValue, @@ -279,6 +280,7 @@ const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; const { ReactCurrentDispatcher, + ReactCurrentCache, ReactCurrentOwner, ReactCurrentBatchConfig, ReactCurrentActQueue, @@ -1790,6 +1792,22 @@ function popDispatcher(prevDispatcher) { ReactCurrentDispatcher.current = prevDispatcher; } +function pushCacheDispatcher() { + if (enableCache) { + const prevCacheDispatcher = ReactCurrentCache.current; + ReactCurrentCache.current = DefaultCacheDispatcher; + return prevCacheDispatcher; + } else { + return null; + } +} + +function popCacheDispatcher(prevCacheDispatcher) { + if (enableCache) { + ReactCurrentCache.current = prevCacheDispatcher; + } +} + export function markCommitTimeOfFallback() { globalMostRecentFallbackTime = now(); } @@ -1857,6 +1875,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) { const prevExecutionContext = executionContext; executionContext |= RenderContext; const prevDispatcher = pushDispatcher(root.containerInfo); + const prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack // and prepare a fresh one. Otherwise we'll continue where we left off. @@ -1903,6 +1922,7 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) { executionContext = prevExecutionContext; popDispatcher(prevDispatcher); + popCacheDispatcher(prevCacheDispatcher); if (workInProgress !== null) { // This is a sync render, so we should have finished the whole tree. @@ -1957,6 +1977,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) { const prevExecutionContext = executionContext; executionContext |= RenderContext; const prevDispatcher = pushDispatcher(root.containerInfo); + const prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack // and prepare a fresh one. Otherwise we'll continue where we left off. @@ -2009,6 +2030,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) { resetContextDependencies(); popDispatcher(prevDispatcher); + popCacheDispatcher(prevCacheDispatcher); executionContext = prevExecutionContext; if (__DEV__) { diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index 2ee501d2a433f..e7b274c3ffd35 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -377,8 +377,6 @@ type Dispatch = A => void; export type Dispatcher = { use?: (Usable) => T, - getCacheSignal?: () => AbortSignal, - getCacheForType?: (resourceType: () => T) => T, readContext(context: ReactContext): T, useState(initialState: (() => S) | S): [S, Dispatch>], useReducer( @@ -432,3 +430,8 @@ export type Dispatcher = { unstable_isNewReconciler?: boolean, }; + +export type CacheDispatcher = { + getCacheSignal: () => AbortSignal, + getCacheForType: (resourceType: () => T) => T, +}; diff --git a/packages/react-server/src/ReactFizzCache.js b/packages/react-server/src/ReactFizzCache.js new file mode 100644 index 0000000000000..f195423e400b6 --- /dev/null +++ b/packages/react-server/src/ReactFizzCache.js @@ -0,0 +1,23 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes'; + +function getCacheSignal(): AbortSignal { + throw new Error('Not implemented.'); +} + +function getCacheForType(resourceType: () => T): T { + throw new Error('Not implemented.'); +} + +export const DefaultCacheDispatcher: CacheDispatcher = { + getCacheSignal, + getCacheForType, +}; diff --git a/packages/react-server/src/ReactFizzHooks.js b/packages/react-server/src/ReactFizzHooks.js index 8db3f319e3cc1..bd0be42d14563 100644 --- a/packages/react-server/src/ReactFizzHooks.js +++ b/packages/react-server/src/ReactFizzHooks.js @@ -8,7 +8,7 @@ */ import type { - Dispatcher as DispatcherType, + Dispatcher, EventFunctionWrapper, } from 'react-reconciler/src/ReactInternalTypes'; @@ -274,12 +274,6 @@ export function resetHooksState(): void { workInProgressHook = null; } -function getCacheForType(resourceType: () => T): T { - // TODO: This should silently mark this as client rendered since it's not necessarily - // considered an error. It needs to work for things like Flight though. - throw new Error('Not implemented.'); -} - function readContext(context: ReactContext): T { if (__DEV__) { if (isInHookUserCodeInDev) { @@ -677,7 +671,7 @@ function useMemoCache(size: number): Array { function noop(): void {} -export const Dispatcher: DispatcherType = { +export const HooksDispatcher: Dispatcher = { readContext, useContext, useMemo, @@ -702,17 +696,16 @@ export const Dispatcher: DispatcherType = { }; if (enableCache) { - Dispatcher.getCacheForType = getCacheForType; - Dispatcher.useCacheRefresh = useCacheRefresh; + HooksDispatcher.useCacheRefresh = useCacheRefresh; } if (enableUseEventHook) { - Dispatcher.useEvent = useEvent; + HooksDispatcher.useEvent = useEvent; } if (enableUseMemoCacheHook) { - Dispatcher.useMemoCache = useMemoCache; + HooksDispatcher.useMemoCache = useMemoCache; } if (enableUseHook) { - Dispatcher.use = use; + HooksDispatcher.use = use; } export let currentResponseState: null | ResponseState = (null: any); diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index 0da6a37ca47da..fe42ccf1cf1e8 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -97,11 +97,12 @@ import { finishHooks, checkDidRenderIdHook, resetHooksState, - Dispatcher, + HooksDispatcher, currentResponseState, setCurrentResponseState, getThenableStateAfterSuspending, } from './ReactFizzHooks'; +import {DefaultCacheDispatcher} from './ReactFizzCache'; import {getStackByComponentStackNode} from './ReactFizzComponentStack'; import {emptyTreeContext, pushTreeContext} from './ReactFizzTreeContext'; @@ -132,6 +133,7 @@ import { enableScopeAPI, enableSuspenseAvoidThisFallbackFizz, enableFloat, + enableCache, } from 'shared/ReactFeatureFlags'; import assign from 'shared/assign'; @@ -140,6 +142,7 @@ import isArray from 'shared/isArray'; import {trackSuspendedWakeable} from './ReactFizzWakeable'; const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; +const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache; const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; type LegacyContext = { @@ -1901,7 +1904,13 @@ export function performWork(request: Request): void { } const prevContext = getActiveContext(); const prevDispatcher = ReactCurrentDispatcher.current; - ReactCurrentDispatcher.current = Dispatcher; + ReactCurrentDispatcher.current = HooksDispatcher; + let prevCacheDispatcher; + if (enableCache) { + prevCacheDispatcher = ReactCurrentCache.current; + ReactCurrentCache.current = DefaultCacheDispatcher; + } + const previousHostDispatcher = prepareToRender(request.resources); let prevGetCurrentStackImpl; if (__DEV__) { @@ -1927,12 +1936,15 @@ export function performWork(request: Request): void { } finally { setCurrentResponseState(prevResponseState); ReactCurrentDispatcher.current = prevDispatcher; + if (enableCache) { + ReactCurrentCache.current = prevCacheDispatcher; + } cleanupAfterRender(previousHostDispatcher); if (__DEV__) { ReactDebugCurrentFrame.getCurrentStack = prevGetCurrentStackImpl; } - if (prevDispatcher === Dispatcher) { + if (prevDispatcher === HooksDispatcher) { // This means that we were in a reentrant work loop. This could happen // in a renderer that supports synchronous work like renderToString, // when it's called from within another renderer. diff --git a/packages/react-server/src/ReactFlightCache.js b/packages/react-server/src/ReactFlightCache.js new file mode 100644 index 0000000000000..4f133c858fc53 --- /dev/null +++ b/packages/react-server/src/ReactFlightCache.js @@ -0,0 +1,43 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes'; + +export const DefaultCacheDispatcher: CacheDispatcher = { + getCacheSignal(): AbortSignal { + throw new Error('Not implemented.'); + }, + getCacheForType(resourceType: () => T): T { + if (!currentCache) { + throw new Error('Reading the cache is only supported while rendering.'); + } + + let entry: T | void = (currentCache.get(resourceType): any); + if (entry === undefined) { + entry = resourceType(); + // TODO: Warn if undefined? + // $FlowFixMe[incompatible-use] found when upgrading Flow + currentCache.set(resourceType, entry); + } + return entry; + }, +}; + +let currentCache: Map | null = null; + +export function setCurrentCache( + cache: Map | null, +): Map | null { + currentCache = cache; + return currentCache; +} + +export function getCurrentCache(): Map | null { + return currentCache; +} diff --git a/packages/react-server/src/ReactFlightHooks.js b/packages/react-server/src/ReactFlightHooks.js index 07de6602e6288..a25a5f4b162ae 100644 --- a/packages/react-server/src/ReactFlightHooks.js +++ b/packages/react-server/src/ReactFlightHooks.js @@ -7,7 +7,7 @@ * @flow */ -import type {Dispatcher as DispatcherType} from 'react-reconciler/src/ReactInternalTypes'; +import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes'; import type {Request} from './ReactFlightServer'; import type {ReactServerContext, Thenable, Usable} from 'shared/ReactTypes'; import type {ThenableState} from './ReactFlightWakeable'; @@ -52,7 +52,7 @@ function readContext(context: ReactServerContext): T { 'Only createServerContext is supported in Server Components.', ); } - if (currentCache === null) { + if (currentRequest === null) { console.error( 'Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + @@ -64,7 +64,7 @@ function readContext(context: ReactServerContext): T { return readContextImpl(context); } -export const Dispatcher: DispatcherType = { +export const HooksDispatcher: Dispatcher = { useMemo(nextCreate: () => T): T { return nextCreate(); }, @@ -74,20 +74,6 @@ export const Dispatcher: DispatcherType = { useDebugValue(): void {}, useDeferredValue: (unsupportedHook: any), useTransition: (unsupportedHook: any), - getCacheForType(resourceType: () => T): T { - if (!currentCache) { - throw new Error('Reading the cache is only supported while rendering.'); - } - - let entry: T | void = (currentCache.get(resourceType): any); - if (entry === undefined) { - entry = resourceType(); - // TODO: Warn if undefined? - // $FlowFixMe[incompatible-use] found when upgrading Flow - currentCache.set(resourceType, entry); - } - return entry; - }, readContext, useContext: readContext, useReducer: (unsupportedHook: any), @@ -114,24 +100,9 @@ function unsupportedHook(): void { } function unsupportedRefresh(): void { - if (!currentCache) { - throw new Error( - 'Refreshing the cache is not supported in Server Components.', - ); - } -} - -let currentCache: Map | null = null; - -export function setCurrentCache( - cache: Map | null, -): Map | null { - currentCache = cache; - return currentCache; -} - -export function getCurrentCache(): Map | null { - return currentCache; + throw new Error( + 'Refreshing the cache is not supported in Server Components.', + ); } function useId(): string { diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 02823183ea949..a4b1d8d7eae8f 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -44,14 +44,17 @@ import { } from './ReactFlightServerConfig'; import { - Dispatcher, - getCurrentCache, + HooksDispatcher, prepareToUseHooksForRequest, prepareToUseHooksForComponent, getThenableStateAfterSuspending, resetHooksForRequest, - setCurrentCache, } from './ReactFlightHooks'; +import { + DefaultCacheDispatcher, + getCurrentCache, + setCurrentCache, +} from './ReactFlightCache'; import { pushProvider, popProvider, @@ -131,6 +134,7 @@ export type Request = { }; const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; +const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache; function defaultErrorHandler(error: mixed) { console['error'](error); @@ -1002,8 +1006,10 @@ function retryTask(request: Request, task: Task): void { function performWork(request: Request): void { const prevDispatcher = ReactCurrentDispatcher.current; + const prevCacheDispatcher = ReactCurrentCache.current; const prevCache = getCurrentCache(); - ReactCurrentDispatcher.current = Dispatcher; + ReactCurrentDispatcher.current = HooksDispatcher; + ReactCurrentCache.current = DefaultCacheDispatcher; setCurrentCache(request.cache); prepareToUseHooksForRequest(request); @@ -1022,6 +1028,7 @@ function performWork(request: Request): void { fatalError(request, error); } finally { ReactCurrentDispatcher.current = prevDispatcher; + ReactCurrentCache.current = prevCacheDispatcher; setCurrentCache(prevCache); resetHooksForRequest(); } diff --git a/packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js b/packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js index abd6cb5779b49..b47a3c044fe76 100644 --- a/packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js +++ b/packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js @@ -7,10 +7,10 @@ * @flow */ -import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes'; +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes'; import ReactSharedInternals from 'shared/ReactSharedInternals'; -const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; +const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache; function unsupported() { throw new Error('This feature is not supported by ReactSuspenseTestUtils.'); @@ -18,7 +18,8 @@ function unsupported() { export function waitForSuspense(fn: () => T): Promise { const cache: Map = new Map(); - const testDispatcher: Dispatcher = { + const testDispatcher: CacheDispatcher = { + getCacheSignal: unsupported, getCacheForType(resourceType: () => R): R { let entry: R | void = (cache.get(resourceType): any); if (entry === undefined) { @@ -28,31 +29,12 @@ export function waitForSuspense(fn: () => T): Promise { } return entry; }, - readContext: unsupported, - useContext: unsupported, - useMemo: unsupported, - useReducer: unsupported, - useRef: unsupported, - useState: unsupported, - useInsertionEffect: unsupported, - useLayoutEffect: unsupported, - useCallback: unsupported, - useImperativeHandle: unsupported, - useEffect: unsupported, - useDebugValue: unsupported, - useDeferredValue: unsupported, - useTransition: unsupported, - useId: unsupported, - useMutableSource: unsupported, - useSyncExternalStore: unsupported, - useCacheRefresh: unsupported, - useMemoCache: unsupported, }; // Not using async/await because we don't compile it. return new Promise((resolve, reject) => { function retry() { - const prevDispatcher = ReactCurrentDispatcher.current; - ReactCurrentDispatcher.current = testDispatcher; + const prevDispatcher = ReactCurrentCache.current; + ReactCurrentCache.current = testDispatcher; try { const result = fn(); resolve(result); @@ -63,7 +45,7 @@ export function waitForSuspense(fn: () => T): Promise { reject(thrownValue); } } finally { - ReactCurrentDispatcher.current = prevDispatcher; + ReactCurrentCache.current = prevDispatcher; } } retry(); diff --git a/packages/react/src/ReactCurrentCache.js b/packages/react/src/ReactCurrentCache.js new file mode 100644 index 0000000000000..6dd825e46fedc --- /dev/null +++ b/packages/react/src/ReactCurrentCache.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes'; + +/** + * Keeps track of the current Cache dispatcher. + */ +const ReactCurrentCache = { + current: (null: null | CacheDispatcher), +}; + +export default ReactCurrentCache; diff --git a/packages/react/src/ReactCurrentDispatcher.js b/packages/react/src/ReactCurrentDispatcher.js index 0d95d5969128e..96e5829f733ae 100644 --- a/packages/react/src/ReactCurrentDispatcher.js +++ b/packages/react/src/ReactCurrentDispatcher.js @@ -13,10 +13,6 @@ import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes'; * Keeps track of the current dispatcher. */ const ReactCurrentDispatcher = { - /** - * @internal - * @type {ReactComponent} - */ current: (null: null | Dispatcher), }; diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index 271a3bae9e680..64e2e561512af 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -18,6 +18,7 @@ import type { } from 'shared/ReactTypes'; import ReactCurrentDispatcher from './ReactCurrentDispatcher'; +import ReactCurrentCache from './ReactCurrentCache'; type BasicStateAction = (S => S) | S; type Dispatch = A => void; @@ -43,14 +44,32 @@ function resolveDispatcher() { } export function getCacheSignal(): AbortSignal { - const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + const dispatcher = ReactCurrentCache.current; + if (!dispatcher) { + // If we have no cache to associate with this call, then we don't know + // its lifetime. We abort early since that's safer than letting it live + // for ever. Unlike just caching which can be a functional noop outside + // of React, these should generally always be associated with some React + // render but we're not limiting quite as much as making it a Hook. + // It's safer than erroring early at runtime. + const controller = new AbortController(); + const reason = new Error( + 'This CacheSignal was requested outside React which means that it is ' + + 'immediately aborted.', + ); + // $FlowFixMe Flow doesn't yet know about this argument. + controller.abort(reason); + return controller.signal; + } return dispatcher.getCacheSignal(); } export function getCacheForType(resourceType: () => T): T { - const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + const dispatcher = ReactCurrentCache.current; + if (!dispatcher) { + // If there is no dispatcher, then we treat this as not being cached. + return resourceType(); + } return dispatcher.getCacheForType(resourceType); } diff --git a/packages/react/src/ReactSharedInternals.js b/packages/react/src/ReactSharedInternals.js index 6f160b96ec8be..aa86af8b440c0 100644 --- a/packages/react/src/ReactSharedInternals.js +++ b/packages/react/src/ReactSharedInternals.js @@ -6,6 +6,7 @@ */ import ReactCurrentDispatcher from './ReactCurrentDispatcher'; +import ReactCurrentCache from './ReactCurrentCache'; import ReactCurrentBatchConfig from './ReactCurrentBatchConfig'; import ReactCurrentActQueue from './ReactCurrentActQueue'; import ReactCurrentOwner from './ReactCurrentOwner'; @@ -15,6 +16,7 @@ import {ContextRegistry} from './ReactServerContextRegistry'; const ReactSharedInternals = { ReactCurrentDispatcher, + ReactCurrentCache, ReactCurrentBatchConfig, ReactCurrentOwner, }; diff --git a/packages/react/src/forks/ReactCurrentDispatcher.www.js b/packages/react/src/forks/ReactCurrentDispatcher.www.js deleted file mode 100644 index d5a784ad6476d..0000000000000 --- a/packages/react/src/forks/ReactCurrentDispatcher.www.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -export default require('ReactCurrentDispatcher'); diff --git a/packages/react/src/forks/ReactCurrentOwner.www.js b/packages/react/src/forks/ReactCurrentOwner.www.js deleted file mode 100644 index c03d11b9deeec..0000000000000 --- a/packages/react/src/forks/ReactCurrentOwner.www.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -export default require('ReactCurrentOwner'); diff --git a/packages/react/src/forks/ReactSharedInternals.umd.js b/packages/react/src/forks/ReactSharedInternals.umd.js index 57e96e6654770..d4f8334017e45 100644 --- a/packages/react/src/forks/ReactSharedInternals.umd.js +++ b/packages/react/src/forks/ReactSharedInternals.umd.js @@ -7,6 +7,7 @@ import * as Scheduler from 'scheduler'; import ReactCurrentDispatcher from '../ReactCurrentDispatcher'; +import ReactCurrentCache from '../ReactCurrentCache'; import ReactCurrentActQueue from '../ReactCurrentActQueue'; import ReactCurrentOwner from '../ReactCurrentOwner'; import ReactDebugCurrentFrame from '../ReactDebugCurrentFrame'; @@ -16,6 +17,7 @@ import {ContextRegistry} from '../ReactServerContextRegistry'; const ReactSharedInternals = { ReactCurrentDispatcher, + ReactCurrentCache, ReactCurrentOwner, ReactCurrentBatchConfig, diff --git a/scripts/error-codes/codes.json b/scripts/error-codes/codes.json index db795a516fe49..278c8d464089a 100644 --- a/scripts/error-codes/codes.json +++ b/scripts/error-codes/codes.json @@ -439,5 +439,6 @@ "451": "resolveSingletonInstance was called with an element type that is not supported. This is a bug in React.", "452": "React expected an element (document.documentElement) to exist in the Document but one was not found. React never removes the documentElement for any Document it renders into so the cause is likely in some other script running on this page.", "453": "React expected a element (document.head) to exist in the Document but one was not found. React never removes the head for any Document it renders into so the cause is likely in some other script running on this page.", - "454": "React expected a element (document.body) to exist in the Document but one was not found. React never removes the body for any Document it renders into so the cause is likely in some other script running on this page." -} + "454": "React expected a element (document.body) to exist in the Document but one was not found. React never removes the body for any Document it renders into so the cause is likely in some other script running on this page.", + "455": "This CacheSignal was requested outside React which means that it is immediately aborted." +} \ No newline at end of file diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index 15856230bacc7..484a1288f8489 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -208,32 +208,6 @@ const forks = Object.freeze({ } }, - // In FB bundles, we preserve an inline require to ReactCurrentOwner. - // See the explanation in FB version of ReactCurrentOwner in www: - './packages/react/src/ReactCurrentOwner.js': (bundleType, entry) => { - switch (bundleType) { - case FB_WWW_DEV: - case FB_WWW_PROD: - case FB_WWW_PROFILING: - return './packages/react/src/forks/ReactCurrentOwner.www.js'; - default: - return null; - } - }, - - // Similarly, we preserve an inline require to ReactCurrentDispatcher. - // See the explanation in FB version of ReactCurrentDispatcher in www: - './packages/react/src/ReactCurrentDispatcher.js': (bundleType, entry) => { - switch (bundleType) { - case FB_WWW_DEV: - case FB_WWW_PROD: - case FB_WWW_PROFILING: - return './packages/react/src/forks/ReactCurrentDispatcher.www.js'; - default: - return null; - } - }, - './packages/react/src/ReactSharedInternals.js': (bundleType, entry) => { switch (bundleType) { case UMD_DEV: