[be] Remove unused, experimental getCacheSignal API (#28706)
Similar to #28698, this removes the `unstable_getCacheSignal()` API since we don't intend to ship this to stable.
Joseph Savona committed
Apr 2, 2024 at 10:54 UTC
8cb6a1c0347a69ad4c580c5cf5f28d8be544d6d4
13 files changed
+2
-67
packages/react-reconciler/src/ReactFiberCache.js
-9
@@ -14,14 +14,6 @@ import {enableCache} from 'shared/ReactFeatureFlags';
14
import {readContext} from './ReactFiberNewContext';
15
import {CacheContext} from './ReactFiberCacheComponent';
16
17
-function getCacheSignal(): AbortSignal {
18
- if (!enableCache) {
19
- throw new Error('Not implemented.');
20
- }
21
- const cache: Cache = readContext(CacheContext);
22
- return cache.controller.signal;
23
-}
24
-
17
function getCacheForType<T>(resourceType: () => T): T {
18
if (!enableCache) {
19
throw new Error('Not implemented.');
@@ -36,6 +28,5 @@ function getCacheForType<T>(resourceType: () => T): T {
28
}
29
30
export const DefaultCacheDispatcher: CacheDispatcher = {
39
- getCacheSignal,
31
getCacheForType,
32
};
packages/react-reconciler/src/ReactInternalTypes.js
-1
@@ -434,6 +434,5 @@ export type Dispatcher = {
434
};
435
436
export type CacheDispatcher = {
437
- getCacheSignal: () => AbortSignal,
437
getCacheForType: <T>(resourceType: () => T) => T,
438
};
packages/react-server/src/ReactFizzCache.js
-5
@@ -9,15 +9,10 @@
9
10
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
11
12
-function getCacheSignal(): AbortSignal {
13
- throw new Error('Not implemented.');
14
-}
15
-
12
function getCacheForType<T>(resourceType: () => T): T {
13
throw new Error('Not implemented.');
14
}
15
16
export const DefaultCacheDispatcher: CacheDispatcher = {
21
- getCacheSignal,
17
getCacheForType,
18
};
packages/react-server/src/flight/ReactFlightServerCache.js
-13
@@ -11,10 +11,6 @@ import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
11
12
import {resolveRequest, getCache} from '../ReactFlightServer';
13
14
-function createSignal(): AbortSignal {
15
- return new AbortController().signal;
16
-}
17
-
14
function resolveCache(): Map<Function, mixed> {
15
const request = resolveRequest();
16
if (request) {
@@ -24,15 +20,6 @@ function resolveCache(): Map<Function, mixed> {
20
}
21
22
export const DefaultCacheDispatcher: CacheDispatcher = {
27
- getCacheSignal(): AbortSignal {
28
- const cache = resolveCache();
29
- let entry: AbortSignal | void = (cache.get(createSignal): any);
30
- if (entry === undefined) {
31
- entry = createSignal();
32
- cache.set(createSignal, entry);
33
- }
34
- return entry;
35
- },
23
getCacheForType<T>(resourceType: () => T): T {
24
const cache = resolveCache();
25
let entry: T | void = (cache.get(resourceType): any);
packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js
-5
@@ -12,14 +12,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
12
13
const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
14
15
-function unsupported() {
16
- throw new Error('This feature is not supported by ReactSuspenseTestUtils.');
17
-}
18
-
15
export function waitForSuspense<T>(fn: () => T): Promise<T> {
16
const cache: Map<Function, mixed> = new Map();
17
const testDispatcher: CacheDispatcher = {
22
- getCacheSignal: unsupported,
18
getCacheForType<R>(resourceType: () => R): R {
19
let entry: R | void = (cache.get(resourceType): any);
20
if (entry === undefined) {
packages/react/index.classic.fb.js
-1
@@ -34,7 +34,6 @@ export {
34
unstable_LegacyHidden,
35
unstable_Scope,
36
unstable_SuspenseList,
37
- unstable_getCacheSignal,
37
unstable_getCacheForType,
38
unstable_useCacheRefresh,
39
unstable_useMemoCache,
packages/react/index.experimental.js
-1
@@ -31,7 +31,6 @@ export {
31
unstable_DebugTracingMode,
32
unstable_Activity,
33
unstable_postpone,
34
- unstable_getCacheSignal,
34
unstable_getCacheForType,
35
unstable_SuspenseList,
36
unstable_useCacheRefresh,
packages/react/index.js
-1
@@ -55,7 +55,6 @@ export {
55
unstable_Scope,
56
unstable_SuspenseList,
57
unstable_TracingMarker,
58
- unstable_getCacheSignal,
58
unstable_getCacheForType,
59
unstable_useCacheRefresh,
60
unstable_useMemoCache,
packages/react/index.modern.fb.js
-1
@@ -33,7 +33,6 @@ export {
33
unstable_Activity,
34
unstable_Scope,
35
unstable_SuspenseList,
36
- unstable_getCacheSignal,
36
unstable_getCacheForType,
37
unstable_useCacheRefresh,
38
unstable_useMemoCache,
packages/react/src/ReactClient.js
-2
@@ -36,7 +36,6 @@ import {memo} from './ReactMemo';
36
import {cache} from './ReactCacheClient';
37
import {postpone} from './ReactPostpone';
38
import {
39
- getCacheSignal,
39
getCacheForType,
40
useCallback,
41
useContext,
@@ -115,7 +114,6 @@ export {
114
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
115
REACT_LEGACY_HIDDEN_TYPE as unstable_LegacyHidden,
116
REACT_OFFSCREEN_TYPE as unstable_Activity,
118
- getCacheSignal as unstable_getCacheSignal,
117
getCacheForType as unstable_getCacheForType,
118
useCacheRefresh as unstable_useCacheRefresh,
119
use,
packages/react/src/ReactFetch.js
+2
-6
@@ -51,12 +51,8 @@ if (enableCache && enableFetchInstrumentation) {
51
// We're outside a cached scope.
52
return originalFetch(resource, options);
53
}
54
- if (
55
- options &&
56
- options.signal &&
57
- options.signal !== dispatcher.getCacheSignal()
58
- ) {
59
- // If we're passed a signal that is not ours, then we assume that
54
+ if (options && options.signal) {
55
+ // If we're passed a signal, then we assume that
56
// someone else controls the lifetime of this object and opts out of
57
// caching. It's effectively the opt-out mechanism.
58
// Ideally we should be able to check this on the Request but
packages/react/src/ReactHooks.js
-20
@@ -43,26 +43,6 @@ function resolveDispatcher() {
43
return ((dispatcher: any): Dispatcher);
44
}
45
46
-export function getCacheSignal(): AbortSignal {
47
- const dispatcher = ReactCurrentCache.current;
48
- if (!dispatcher) {
49
- // If we have no cache to associate with this call, then we don't know
50
- // its lifetime. We abort early since that's safer than letting it live
51
- // for ever. Unlike just caching which can be a functional noop outside
52
- // of React, these should generally always be associated with some React
53
- // render but we're not limiting quite as much as making it a Hook.
54
- // It's safer than erroring early at runtime.
55
- const controller = new AbortController();
56
- const reason = new Error(
57
- 'This CacheSignal was requested outside React which means that it is ' +
58
- 'immediately aborted.',
59
- );
60
- controller.abort(reason);
61
- return controller.signal;
62
- }
63
- return dispatcher.getCacheSignal();
64
-}
65
-
46
export function getCacheForType<T>(resourceType: () => T): T {
47
const dispatcher = ReactCurrentCache.current;
48
if (!dispatcher) {
packages/react/src/ReactServer.experimental.js
-2
@@ -35,7 +35,6 @@ import {
35
useDebugValue,
36
useMemo,
37
useActionState,
38
- getCacheSignal,
38
getCacheForType,
39
} from './ReactHooks';
40
import {forwardRef} from './ReactForwardRef';
@@ -78,7 +77,6 @@ export {
77
startTransition,
78
REACT_DEBUG_TRACING_MODE_TYPE as unstable_DebugTracingMode,
79
REACT_SUSPENSE_TYPE as unstable_SuspenseList,
81
- getCacheSignal as unstable_getCacheSignal,
80
getCacheForType as unstable_getCacheForType,
81
postpone as unstable_postpone,
82
useId,