Home / File/ ReactServerConsoleConfigBrowser.js — react Source File

ReactServerConsoleConfigBrowser.js — react Source File

Architecture documentation for ReactServerConsoleConfigBrowser.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

/**
 * 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
 */

// Keep in sync with ReactClientConsoleConfig
const badgeFormat = '%c%s%c';
// Same badge styling as DevTools.
const badgeStyle =
  // We use a fixed background if light-dark is not supported, otherwise
  // we use a transparent background.
  'background: #e6e6e6;' +
  'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' +
  'color: #000000;' +
  'color: light-dark(#000000, #ffffff);' +
  'border-radius: 2px';

const padLength = 1;

// This mutates the args to remove any badges that was added by a FlightClient and
// returns the name in the badge. This is used when a FlightClient replays inside
// a FlightServer and we capture those replays.
export function unbadgeConsole(
  methodName: string,
  args: Array<any>,
): null | string {
  let offset = 0;
  switch (methodName) {
    case 'dir':
    case 'dirxml':
    case 'groupEnd':
    case 'table': {
      // These methods cannot be colorized because they don't take a formatting string.
      // So we wouldn't have added any badge in the first place.
      // $FlowFixMe
      return null;
    }
    case 'assert': {
      // assert takes formatting options as the second argument.
      offset = 1;
    }
  }
  const format = args[offset];
  const style = args[offset + 1];
  const badge = args[offset + 2];
  if (
    typeof format === 'string' &&
    format.startsWith(badgeFormat) &&
    style === badgeStyle &&
    typeof badge === 'string'
  ) {
    // Remove our badging from the arguments.
    let unbadgedFormat = format.slice(badgeFormat.length);
    if (unbadgedFormat[0] === ' ') {
      // Spacing added on the Client if the original argument was a string.
      unbadgedFormat = unbadgedFormat.slice(1);
    }
    args.splice(offset, 4, unbadgedFormat);
    return badge.slice(padLength, badge.length - padLength);
  }
  return null;
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does ReactServerConsoleConfigBrowser.js do?
ReactServerConsoleConfigBrowser.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactServerConsoleConfigBrowser.js?
ReactServerConsoleConfigBrowser.js defines 1 function(s): unbadgeConsole.
Where is ReactServerConsoleConfigBrowser.js in the architecture?
ReactServerConsoleConfigBrowser.js is located at packages/react-server/src/ReactServerConsoleConfigBrowser.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-server/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free