Repository: facebook/react
File: packages/react/src/ReactServerContext.js (JavaScript)

Code before:
  REACT_SERVER_CONTEXT_TYPE,
  REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED,
} from 'shared/ReactSymbols';

import type {
  ReactServerContext,
  ServerContextJSONValue,
} from 'shared/ReactTypes';

import {enableServerContext} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';

const ContextRegistry = ReactSharedInternals.ContextRegistry;

export function createServerContext<T: ServerContextJSONValue>(
  globalName: string,
  defaultValue: T,
): ReactServerContext<T> {
  if (!enableServerContext) {
    throw new Error('Not implemented.');
  }
  if (__DEV__) {
    console.error(
      'Server Context is deprecated and will soon be removed. ' +
        'It was never documented and we have found it not to be useful ' +
        'enough to warrant the downside it emposes on all apps.',
    );
  }
  let wasDefined = true;
  if (!ContextRegistry[globalName]) {
    wasDefined = false;
    const context: ReactServerContext<T> = {
      $$typeof: REACT_SERVER_CONTEXT_TYPE,

      // As a workaround to support multiple concurrent renderers, we categorize
      // some renderers as primary and others as secondary. We only expect
      // there to be two concurrent renderers at most: React Native (primary) and
      // Fabric (secondary); React DOM (primary) and React ART (secondary).
      // Secondary renderers store their context values on separate fields.
      _currentValue: defaultValue,
      _currentValue2: defaultValue,

      _defaultValue: defaultValue,

      // Used to track how many concurrent renderers this context currently
      // supports within in a single renderer. Such as parallel server rendering.
      _threadCount: 0,
      // These are circular
      Provider: (null: any),
      Consumer: (null: any),
      _globalName: globalName,

Review comment (suggestion):
```suggestion
        'enough to warrant the downside it imposes on all apps.',
```

Code after:
  REACT_SERVER_CONTEXT_TYPE,
  REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED,
} from 'shared/ReactSymbols';

import type {
  ReactServerContext,
  ServerContextJSONValue,
} from 'shared/ReactTypes';

import {enableServerContext} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';

const ContextRegistry = ReactSharedInternals.ContextRegistry;

export function createServerContext<T: ServerContextJSONValue>(
  globalName: string,
  defaultValue: T,
): ReactServerContext<T> {
  if (!enableServerContext) {
    throw new Error('Not implemented.');
  }
  if (__DEV__) {
    console.error(
      'Server Context is deprecated and will soon be removed. ' +
        'It was never documented and we have found it not to be useful ' +
        'enough to warrant the downside it imposes on all apps.',
    );
  }
  let wasDefined = true;
  if (!ContextRegistry[globalName]) {
    wasDefined = false;
    const context: ReactServerContext<T> = {
      $$typeof: REACT_SERVER_CONTEXT_TYPE,

      // As a workaround to support multiple concurrent renderers, we categorize
      // some renderers as primary and others as secondary. We only expect
      // there to be two concurrent renderers at most: React Native (primary) and
      // Fabric (secondary); React DOM (primary) and React ART (secondary).
      // Secondary renderers store their context values on separate fields.
      _currentValue: defaultValue,
      _currentValue2: defaultValue,

      _defaultValue: defaultValue,

      // Used to track how many concurrent renderers this context currently
      // supports within in a single renderer. Such as parallel server rendering.
      _threadCount: 0,
      // These are circular
      Provider: (null: any),
      Consumer: (null: any),
      _globalName: globalName,