Skip to content

Commit 8cb6a1c

Browse files
authored
[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.
1 parent 48ec17b commit 8cb6a1c

13 files changed

+2
-67
lines changed

packages/react-reconciler/src/ReactFiberCache.js

-9
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ import {enableCache} from 'shared/ReactFeatureFlags';
1414
import {readContext} from './ReactFiberNewContext';
1515
import {CacheContext} from './ReactFiberCacheComponent';
1616

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-
2517
function getCacheForType<T>(resourceType: () => T): T {
2618
if (!enableCache) {
2719
throw new Error('Not implemented.');
@@ -36,6 +28,5 @@ function getCacheForType<T>(resourceType: () => T): T {
3628
}
3729

3830
export const DefaultCacheDispatcher: CacheDispatcher = {
39-
getCacheSignal,
4031
getCacheForType,
4132
};

packages/react-reconciler/src/ReactInternalTypes.js

-1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,5 @@ export type Dispatcher = {
434434
};
435435

436436
export type CacheDispatcher = {
437-
getCacheSignal: () => AbortSignal,
438437
getCacheForType: <T>(resourceType: () => T) => T,
439438
};

packages/react-server/src/ReactFizzCache.js

-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@
99

1010
import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
1111

12-
function getCacheSignal(): AbortSignal {
13-
throw new Error('Not implemented.');
14-
}
15-
1612
function getCacheForType<T>(resourceType: () => T): T {
1713
throw new Error('Not implemented.');
1814
}
1915

2016
export const DefaultCacheDispatcher: CacheDispatcher = {
21-
getCacheSignal,
2217
getCacheForType,
2318
};

packages/react-server/src/flight/ReactFlightServerCache.js

-13
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
1111

1212
import {resolveRequest, getCache} from '../ReactFlightServer';
1313

14-
function createSignal(): AbortSignal {
15-
return new AbortController().signal;
16-
}
17-
1814
function resolveCache(): Map<Function, mixed> {
1915
const request = resolveRequest();
2016
if (request) {
@@ -24,15 +20,6 @@ function resolveCache(): Map<Function, mixed> {
2420
}
2521

2622
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-
},
3623
getCacheForType<T>(resourceType: () => T): T {
3724
const cache = resolveCache();
3825
let entry: T | void = (cache.get(resourceType): any);

packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js

-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
1212

1313
const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1414

15-
function unsupported() {
16-
throw new Error('This feature is not supported by ReactSuspenseTestUtils.');
17-
}
18-
1915
export function waitForSuspense<T>(fn: () => T): Promise<T> {
2016
const cache: Map<Function, mixed> = new Map();
2117
const testDispatcher: CacheDispatcher = {
22-
getCacheSignal: unsupported,
2318
getCacheForType<R>(resourceType: () => R): R {
2419
let entry: R | void = (cache.get(resourceType): any);
2520
if (entry === undefined) {

packages/react/index.classic.fb.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export {
3434
unstable_LegacyHidden,
3535
unstable_Scope,
3636
unstable_SuspenseList,
37-
unstable_getCacheSignal,
3837
unstable_getCacheForType,
3938
unstable_useCacheRefresh,
4039
unstable_useMemoCache,

packages/react/index.experimental.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export {
3131
unstable_DebugTracingMode,
3232
unstable_Activity,
3333
unstable_postpone,
34-
unstable_getCacheSignal,
3534
unstable_getCacheForType,
3635
unstable_SuspenseList,
3736
unstable_useCacheRefresh,

packages/react/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export {
5555
unstable_Scope,
5656
unstable_SuspenseList,
5757
unstable_TracingMarker,
58-
unstable_getCacheSignal,
5958
unstable_getCacheForType,
6059
unstable_useCacheRefresh,
6160
unstable_useMemoCache,

packages/react/index.modern.fb.js

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export {
3333
unstable_Activity,
3434
unstable_Scope,
3535
unstable_SuspenseList,
36-
unstable_getCacheSignal,
3736
unstable_getCacheForType,
3837
unstable_useCacheRefresh,
3938
unstable_useMemoCache,

packages/react/src/ReactClient.js

-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {memo} from './ReactMemo';
3636
import {cache} from './ReactCacheClient';
3737
import {postpone} from './ReactPostpone';
3838
import {
39-
getCacheSignal,
4039
getCacheForType,
4140
useCallback,
4241
useContext,
@@ -115,7 +114,6 @@ export {
115114
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
116115
REACT_LEGACY_HIDDEN_TYPE as unstable_LegacyHidden,
117116
REACT_OFFSCREEN_TYPE as unstable_Activity,
118-
getCacheSignal as unstable_getCacheSignal,
119117
getCacheForType as unstable_getCacheForType,
120118
useCacheRefresh as unstable_useCacheRefresh,
121119
use,

packages/react/src/ReactFetch.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ if (enableCache && enableFetchInstrumentation) {
5151
// We're outside a cached scope.
5252
return originalFetch(resource, options);
5353
}
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
6056
// someone else controls the lifetime of this object and opts out of
6157
// caching. It's effectively the opt-out mechanism.
6258
// Ideally we should be able to check this on the Request but

packages/react/src/ReactHooks.js

-20
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ function resolveDispatcher() {
4343
return ((dispatcher: any): Dispatcher);
4444
}
4545

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-
6646
export function getCacheForType<T>(resourceType: () => T): T {
6747
const dispatcher = ReactCurrentCache.current;
6848
if (!dispatcher) {

packages/react/src/ReactServer.experimental.js

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
useDebugValue,
3636
useMemo,
3737
useActionState,
38-
getCacheSignal,
3938
getCacheForType,
4039
} from './ReactHooks';
4140
import {forwardRef} from './ReactForwardRef';
@@ -78,7 +77,6 @@ export {
7877
startTransition,
7978
REACT_DEBUG_TRACING_MODE_TYPE as unstable_DebugTracingMode,
8079
REACT_SUSPENSE_TYPE as unstable_SuspenseList,
81-
getCacheSignal as unstable_getCacheSignal,
8280
getCacheForType as unstable_getCacheForType,
8381
postpone as unstable_postpone,
8482
useId,

0 commit comments

Comments
 (0)