Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add stubs to the AsyncDispatcher
  • Loading branch information
sebmarkbage committed Jun 17, 2025
commit ddf6d03b29dabd5e621e529281134ca67b834f69
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactFiberAsyncDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ function getCacheForType<T>(resourceType: () => T): T {
return cacheForType;
}

function cacheSignal(): null | AbortSignal {
return null;
}

export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType,
cacheSignal,
}: any);

if (__DEV__) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export type Dispatcher = {

export type AsyncDispatcher = {
getCacheForType: <T>(resourceType: () => T) => T,
cacheSignal: () => null | AbortSignal,
// DEV-only
getOwner: () => null | Fiber | ReactComponentInfo | ComponentStackNode,
};
5 changes: 5 additions & 0 deletions packages/react-server/src/ReactFizzAsyncDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ function getCacheForType<T>(resourceType: () => T): T {
throw new Error('Not implemented.');
}

function cacheSignal(): null | AbortSignal {
throw new Error('Not implemented.');
}

export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType,
cacheSignal,
}: any);

if (__DEV__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const DefaultAsyncDispatcher: AsyncDispatcher = ({
}
return entry;
},
cacheSignal(): null | AbortSignal {
return null;
},
}: any);

if (__DEV__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
}
return entry;
},
cacheSignal(): null {
return null;
},
getOwner(): null {
return null;
},
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/ReactCacheImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,13 @@ export function cache<A: Iterable<mixed>, T>(fn: (...A) => T): (...A) => T {
}

export function cacheSignal(): null | AbortSignal {
return null;
const dispatcher = ReactSharedInternals.A;
if (!dispatcher) {
// If there is no dispatcher, then we treat this as not having an AbortSignal
// since in the same context, a cached function will be allowed to be called
// but it won't be cached. So it's neither an infinite AbortSignal nor an
// already resolved one.
return null;
}
return dispatcher.cacheSignal();
}