mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d50323eb84
This is similar to #28771 but for isomorphic. We need a make over for these dispatchers anyway so this is the first step. Also helps flush out some internals usage that will break anyway. It flattens the inner mutable objects onto the ReactSharedInternals.
79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import type {Fiber} from './ReactInternalTypes';
|
|
|
|
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
|
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
|
|
import {getComponentNameFromOwner} from 'react-reconciler/src/getComponentNameFromFiber';
|
|
|
|
export let current: Fiber | null = null;
|
|
export let isRendering: boolean = false;
|
|
|
|
export function getCurrentFiberOwnerNameInDevOrNull(): string | null {
|
|
if (__DEV__) {
|
|
if (current === null) {
|
|
return null;
|
|
}
|
|
const owner = current._debugOwner;
|
|
if (owner != null) {
|
|
return getComponentNameFromOwner(owner);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function getCurrentFiberStackInDev(): string {
|
|
if (__DEV__) {
|
|
if (current === null) {
|
|
return '';
|
|
}
|
|
// Safe because if current fiber exists, we are reconciling,
|
|
// and it is guaranteed to be the work-in-progress version.
|
|
return getStackByFiberInDevAndProd(current);
|
|
}
|
|
return '';
|
|
}
|
|
|
|
export function resetCurrentFiber() {
|
|
if (__DEV__) {
|
|
ReactSharedInternals.getCurrentStack = null;
|
|
current = null;
|
|
isRendering = false;
|
|
}
|
|
}
|
|
|
|
export function setCurrentFiber(fiber: Fiber | null) {
|
|
if (__DEV__) {
|
|
ReactSharedInternals.getCurrentStack =
|
|
fiber === null ? null : getCurrentFiberStackInDev;
|
|
current = fiber;
|
|
isRendering = false;
|
|
}
|
|
}
|
|
|
|
export function getCurrentFiber(): Fiber | null {
|
|
if (__DEV__) {
|
|
return current;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function setIsRendering(rendering: boolean) {
|
|
if (__DEV__) {
|
|
isRendering = rendering;
|
|
}
|
|
}
|
|
|
|
export function getIsRendering(): void | boolean {
|
|
if (__DEV__) {
|
|
return isRendering;
|
|
}
|
|
}
|