diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 8066213aa0..631362fd7d 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -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( 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); diff --git a/packages/react-server/src/flight/ReactFlightAsyncDispatcher.js b/packages/react-server/src/flight/ReactFlightAsyncDispatcher.js index 8ff0cd5bc9..1cdd67a821 100644 --- a/packages/react-server/src/flight/ReactFlightAsyncDispatcher.js +++ b/packages/react-server/src/flight/ReactFlightAsyncDispatcher.js @@ -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; +}