Same thing for Flight

This will later use AsyncLocalStorage to track this just like the cache.
This commit is contained in:
Sebastian Markbage
2024-04-22 12:05:45 -04:00
committed by Rick Hanlon
parent b217f5adf1
commit afaf8a1f67
2 changed files with 15 additions and 6 deletions
+8 -4
View File
@@ -89,7 +89,11 @@ import {
getThenableStateAfterSuspending,
resetHooksForRequest,
} from './ReactFlightHooks';
import {DefaultAsyncDispatcher} from './flight/ReactFlightAsyncDispatcher';
import {
DefaultAsyncDispatcher,
currentOwner,
setCurrentOwner,
} from './flight/ReactFlightAsyncDispatcher';
import {
getIteratorFn,
@@ -158,7 +162,7 @@ function patchConsole(consoleInst: typeof console, methodName: string) {
// We don't currently use this id for anything but we emit it so that we can later
// refer to previous logs in debug info to associate them with a component.
const id = request.nextChunkId++;
const owner: null | ReactComponentInfo = ReactSharedInternals.owner;
const owner: null | ReactComponentInfo = currentOwner;
emitConsoleChunk(request, id, methodName, owner, stack, arguments);
}
// $FlowFixMe[prop-missing]
@@ -854,11 +858,11 @@ function renderFunctionComponent<Props>(
const secondArg = undefined;
let result;
if (__DEV__) {
ReactSharedInternals.owner = componentDebugInfo;
setCurrentOwner(componentDebugInfo);
try {
result = Component(props, secondArg);
} finally {
ReactSharedInternals.owner = null;
setCurrentOwner(null);
}
} else {
result = Component(props, secondArg);
@@ -36,10 +36,11 @@ export const DefaultAsyncDispatcher: AsyncDispatcher = ({
},
}: any);
export let currentOwner: ReactComponentInfo | null = null;
if (__DEV__) {
DefaultAsyncDispatcher.getOwner = (): null | ReactComponentInfo => {
// TODO
return null;
return currentOwner;
};
} else if (!disableStringRefs) {
// Server Components never use string refs but the JSX runtime looks for it.
@@ -47,3 +48,7 @@ if (__DEV__) {
return null;
};
}
export function setCurrentOwner(componentInfo: null | ReactComponentInfo) {
currentOwner = componentInfo;
}