Add getOwner on the AsyncDispatcher

This commit is contained in:
Sebastian Markbage
2024-04-22 12:05:45 -04:00
committed by Rick Hanlon
parent d5d6023a01
commit d87e6e4e07
5 changed files with 46 additions and 7 deletions
+12 -3
View File
@@ -7,13 +7,15 @@
* @flow
*/
import type {AsyncDispatcher} from './ReactInternalTypes';
import type {AsyncDispatcher, Fiber} from './ReactInternalTypes';
import type {Cache} from './ReactFiberCacheComponent';
import {enableCache} from 'shared/ReactFeatureFlags';
import {readContext} from './ReactFiberNewContext';
import {CacheContext} from './ReactFiberCacheComponent';
import {disableStringRefs} from 'shared/ReactFeatureFlags';
function getCacheForType<T>(resourceType: () => T): T {
if (!enableCache) {
throw new Error('Not implemented.');
@@ -27,6 +29,13 @@ function getCacheForType<T>(resourceType: () => T): T {
return cacheForType;
}
export const DefaultAsyncDispatcher: AsyncDispatcher = {
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType,
};
}: any);
if (__DEV__ || !disableStringRefs) {
DefaultAsyncDispatcher.getOwner = (): null | Fiber => {
// TODO
return null;
};
}
+2
View File
@@ -436,4 +436,6 @@ export type Dispatcher = {
export type AsyncDispatcher = {
getCacheForType: <T>(resourceType: () => T) => T,
// DEV-only (or !disableStringRefs)
getOwner: () => null | Fiber | ReactComponentInfo,
};
+11 -2
View File
@@ -9,10 +9,19 @@
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
import {disableStringRefs} from 'shared/ReactFeatureFlags';
function getCacheForType<T>(resourceType: () => T): T {
throw new Error('Not implemented.');
}
export const DefaultAsyncDispatcher: AsyncDispatcher = {
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType,
};
}: any);
if (__DEV__ || !disableStringRefs) {
// Fizz never tracks owner but the JSX runtime looks for this.
DefaultAsyncDispatcher.getOwner = (): null => {
return null;
};
}
+18 -2
View File
@@ -7,10 +7,14 @@
* @flow
*/
import type {ReactComponentInfo} from 'shared/ReactTypes';
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
import {resolveRequest, getCache} from '../ReactFlightServer';
import {disableStringRefs} from 'shared/ReactFeatureFlags';
function resolveCache(): Map<Function, mixed> {
const request = resolveRequest();
if (request) {
@@ -19,7 +23,7 @@ function resolveCache(): Map<Function, mixed> {
return new Map();
}
export const DefaultAsyncDispatcher: AsyncDispatcher = {
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType<T>(resourceType: () => T): T {
const cache = resolveCache();
let entry: T | void = (cache.get(resourceType): any);
@@ -30,4 +34,16 @@ export const DefaultAsyncDispatcher: AsyncDispatcher = {
}
return entry;
},
};
}: any);
if (__DEV__) {
DefaultAsyncDispatcher.getOwner = (): null | ReactComponentInfo => {
// TODO
return null;
};
} else if (!disableStringRefs) {
// Server Components never use string refs but the JSX runtime looks for it.
DefaultAsyncDispatcher.getOwner = (): null | ReactComponentInfo => {
return null;
};
}
@@ -22,6 +22,9 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
}
return entry;
},
getOwner(): null {
return null;
},
};
// Not using async/await because we don't compile it.
return new Promise((resolve, reject) => {