Skip to content

Commit

Permalink
[be] Remove unused, experimental getCacheSignal API (#28706)
Browse files Browse the repository at this point in the history
Similar to #28698, this removes the `unstable_getCacheSignal()` API
since we don't intend to ship this to stable.
  • Loading branch information
josephsavona committed Apr 2, 2024
1 parent 48ec17b commit 8cb6a1c
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 67 deletions.
9 changes: 0 additions & 9 deletions packages/react-reconciler/src/ReactFiberCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ import {enableCache} from 'shared/ReactFeatureFlags';
import {readContext} from './ReactFiberNewContext';
import {CacheContext} from './ReactFiberCacheComponent';

function getCacheSignal(): AbortSignal {
if (!enableCache) {
throw new Error('Not implemented.');
}
const cache: Cache = readContext(CacheContext);
return cache.controller.signal;
}

function getCacheForType<T>(resourceType: () => T): T {
if (!enableCache) {
throw new Error('Not implemented.');
Expand All @@ -36,6 +28,5 @@ function getCacheForType<T>(resourceType: () => T): T {
}

export const DefaultCacheDispatcher: CacheDispatcher = {
getCacheSignal,
getCacheForType,
};
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,5 @@ export type Dispatcher = {
};

export type CacheDispatcher = {
getCacheSignal: () => AbortSignal,
getCacheForType: <T>(resourceType: () => T) => T,
};
5 changes: 0 additions & 5 deletions packages/react-server/src/ReactFizzCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

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

function getCacheSignal(): AbortSignal {
throw new Error('Not implemented.');
}

function getCacheForType<T>(resourceType: () => T): T {
throw new Error('Not implemented.');
}

export const DefaultCacheDispatcher: CacheDispatcher = {
getCacheSignal,
getCacheForType,
};
13 changes: 0 additions & 13 deletions packages/react-server/src/flight/ReactFlightServerCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';

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

function createSignal(): AbortSignal {
return new AbortController().signal;
}

function resolveCache(): Map<Function, mixed> {
const request = resolveRequest();
if (request) {
Expand All @@ -24,15 +20,6 @@ function resolveCache(): Map<Function, mixed> {
}

export const DefaultCacheDispatcher: CacheDispatcher = {
getCacheSignal(): AbortSignal {
const cache = resolveCache();
let entry: AbortSignal | void = (cache.get(createSignal): any);
if (entry === undefined) {
entry = createSignal();
cache.set(createSignal, entry);
}
return entry;
},
getCacheForType<T>(resourceType: () => T): T {
const cache = resolveCache();
let entry: T | void = (cache.get(resourceType): any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';

const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;

function unsupported() {
throw new Error('This feature is not supported by ReactSuspenseTestUtils.');
}

export function waitForSuspense<T>(fn: () => T): Promise<T> {
const cache: Map<Function, mixed> = new Map();
const testDispatcher: CacheDispatcher = {
getCacheSignal: unsupported,
getCacheForType<R>(resourceType: () => R): R {
let entry: R | void = (cache.get(resourceType): any);
if (entry === undefined) {
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export {
unstable_LegacyHidden,
unstable_Scope,
unstable_SuspenseList,
unstable_getCacheSignal,
unstable_getCacheForType,
unstable_useCacheRefresh,
unstable_useMemoCache,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export {
unstable_DebugTracingMode,
unstable_Activity,
unstable_postpone,
unstable_getCacheSignal,
unstable_getCacheForType,
unstable_SuspenseList,
unstable_useCacheRefresh,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export {
unstable_Scope,
unstable_SuspenseList,
unstable_TracingMarker,
unstable_getCacheSignal,
unstable_getCacheForType,
unstable_useCacheRefresh,
unstable_useMemoCache,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export {
unstable_Activity,
unstable_Scope,
unstable_SuspenseList,
unstable_getCacheSignal,
unstable_getCacheForType,
unstable_useCacheRefresh,
unstable_useMemoCache,
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/ReactClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {memo} from './ReactMemo';
import {cache} from './ReactCacheClient';
import {postpone} from './ReactPostpone';
import {
getCacheSignal,
getCacheForType,
useCallback,
useContext,
Expand Down Expand Up @@ -115,7 +114,6 @@ export {
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
REACT_LEGACY_HIDDEN_TYPE as unstable_LegacyHidden,
REACT_OFFSCREEN_TYPE as unstable_Activity,
getCacheSignal as unstable_getCacheSignal,
getCacheForType as unstable_getCacheForType,
useCacheRefresh as unstable_useCacheRefresh,
use,
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/ReactFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ if (enableCache && enableFetchInstrumentation) {
// We're outside a cached scope.
return originalFetch(resource, options);
}
if (
options &&
options.signal &&
options.signal !== dispatcher.getCacheSignal()
) {
// If we're passed a signal that is not ours, then we assume that
if (options && options.signal) {
// If we're passed a signal, then we assume that
// someone else controls the lifetime of this object and opts out of
// caching. It's effectively the opt-out mechanism.
// Ideally we should be able to check this on the Request but
Expand Down
20 changes: 0 additions & 20 deletions packages/react/src/ReactHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,6 @@ function resolveDispatcher() {
return ((dispatcher: any): Dispatcher);
}

export function getCacheSignal(): AbortSignal {
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.',
);
controller.abort(reason);
return controller.signal;
}
return dispatcher.getCacheSignal();
}

export function getCacheForType<T>(resourceType: () => T): T {
const dispatcher = ReactCurrentCache.current;
if (!dispatcher) {
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/ReactServer.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
useDebugValue,
useMemo,
useActionState,
getCacheSignal,
getCacheForType,
} from './ReactHooks';
import {forwardRef} from './ReactForwardRef';
Expand Down Expand Up @@ -78,7 +77,6 @@ export {
startTransition,
REACT_DEBUG_TRACING_MODE_TYPE as unstable_DebugTracingMode,
REACT_SUSPENSE_TYPE as unstable_SuspenseList,
getCacheSignal as unstable_getCacheSignal,
getCacheForType as unstable_getCacheForType,
postpone as unstable_postpone,
useId,
Expand Down

0 comments on commit 8cb6a1c

Please sign in to comment.