Repository: facebook/react
File: packages/react-devtools-shared/src/backend/fiber/renderer.js (JavaScript)

Code before:
import type {Source} from 'react-devtools-shared/src/shared/types';
import {getStackByFiberInDevAndProd} from './DevToolsFiberComponentStack';

// Kinds
const FIBER_INSTANCE = 0;
const VIRTUAL_INSTANCE = 1;

// Flags
const FORCE_SUSPENSE_FALLBACK = /*    */ 0b001;
const FORCE_ERROR = /*                */ 0b010;
const FORCE_ERROR_RESET = /*          */ 0b100;

// This type represents a stateful instance of a Client Component i.e. a Fiber pair.
// These instances also let us track stateful DevTools meta data like id and warnings.
type FiberInstance = {
  kind: 0,
  id: number,
  parent: null | DevToolsInstance, // filtered parent, including virtual
  firstChild: null | DevToolsInstance, // filtered first child, including virtual
  previousSibling: null | DevToolsInstance, // filtered next sibling, including virtual
  nextSibling: null | DevToolsInstance, // filtered next sibling, including virtual
  flags: number, // Force Error/Suspense
  componentStack: null | string,
  errors: null | Map<string, number>, // error messages and count
  warnings: null | Map<string, number>, // warning messages and count
  data: Fiber, // one of a Fiber pair
};

function createFiberInstance(fiber: Fiber): FiberInstance {
  return {
    kind: FIBER_INSTANCE,
    id: getUID(),
    parent: null,
    firstChild: null,
    previousSibling: null,
    nextSibling: null,
    flags: 0,
    componentStack: null,
    errors: null,
    warnings: null,
    data: fiber,
  };
}

// This type represents a stateful instance of a Server Component or a Component
// that gets optimized away - e.g. call-through without creating a Fiber.
// It's basically a virtual Fiber. This is not a semantic concept in React.
// It only exists as a virtual concept to let the same Element in the DevTools
// persist. To be selectable separately from all ReactComponentInfo and overtime.
type VirtualInstance = {
  kind: 1,

Review comment (suggestion):
This is one unnecessary field when isProfilingSupported isn't true (i.e. in production only builds). We could potentially make that conditionally added based on build but doesn't seem worth it. It's not worse otherwise since we added a map entry for everything otherwise.

Code after:
import type {Source} from 'react-devtools-shared/src/shared/types';
import {getStackByFiberInDevAndProd} from './DevToolsFiberComponentStack';

// Kinds
const FIBER_INSTANCE = 0;
const VIRTUAL_INSTANCE = 1;

// Flags
const FORCE_SUSPENSE_FALLBACK = /*    */ 0b001;
const FORCE_ERROR = /*                */ 0b010;
const FORCE_ERROR_RESET = /*          */ 0b100;

// This type represents a stateful instance of a Client Component i.e. a Fiber pair.
// These instances also let us track stateful DevTools meta data like id and warnings.
type FiberInstance = {
  kind: 0,
  id: number,
  parent: null | DevToolsInstance, // filtered parent, including virtual
  firstChild: null | DevToolsInstance, // filtered first child, including virtual
  previousSibling: null | DevToolsInstance, // filtered next sibling, including virtual
  nextSibling: null | DevToolsInstance, // filtered next sibling, including virtual
  flags: number, // Force Error/Suspense
  componentStack: null | string,
  errors: null | Map<string, number>, // error messages and count
  warnings: null | Map<string, number>, // warning messages and count
  treeBaseDuration: number, // the profiled time of the last render of this subtree
  data: Fiber, // one of a Fiber pair
};

function createFiberInstance(fiber: Fiber): FiberInstance {
  return {
    kind: FIBER_INSTANCE,
    id: getUID(),
    parent: null,
    firstChild: null,
    previousSibling: null,
    nextSibling: null,
    flags: 0,
    componentStack: null,
    errors: null,
    warnings: null,
    treeBaseDuration: 0,
    data: fiber,
  };
}

// This type represents a stateful instance of a Server Component or a Component
// that gets optimized away - e.g. call-through without creating a Fiber.
// It's basically a virtual Fiber. This is not a semantic concept in React.
// It only exists as a virtual concept to let the same Element in the DevTools
// persist. To be selectable separately from all ReactComponentInfo and overtime.