facebook/lexical · info

message

Error message

message

What it means

warnOnlyOnce is a utility that returns a function which logs a given message via console.warn only the first time it is invoked; subsequent calls are no-ops (and in production it always returns a no-op). The message string shown here is literally whatever string the caller passed as `message`. It exists so libraries can warn about misuse without spamming the console on every occurrence.

Source

Thrown at packages/lexical-internal/src/warnOnlyOnce.ts:17

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

const __DEV__ = process.env.NODE_ENV !== 'production';

/*@__INLINE__*/
export default function warnOnlyOnce(message: string): () => void {
  if (__DEV__) {
    let run = false;
    return () => {
      if (!run) {
        console.warn(message);
      }
      run = true;
    };
  } else {
    return () => {};
  }
}

View on GitHub (pinned to 76a22dcba9)

Solutions

  1. Read the actual `message` argument logged alongside — it carries the real diagnostic; fix whatever condition that message describes.
  2. If it is your own code, ensure warnOnlyOnce is only called with a fully descriptive message since it is the user's only signal.
  3. No action needed in production builds: the returned function is a no-op when __DEV__ is false.

Example fix

// before
const warn = warnOnlyOnce('');
warn();
// after
const warn = warnOnlyOnce('Lexical: deprecated $foo() used; migrate to $bar()');
warn(); // logs once
Defensive patterns

Strategy: validation

Validate before calling

if (typeof message !== 'string' || message.length === 0) throw new Error('warnOnlyOnce requires a descriptive message');

Prevention

When it happens

Trigger: Calling the function returned by warnOnlyOnce('...') more than once causes the warn only once; the warn fires when the returned function is first called, typically from a dev-only code path detecting a misuse (e.g. deprecated API use, invalid configuration).

Common situations: Seeing this logged means some Lexical internal/dev warning was emitted one time — the actual message text is supplied by the call site of warnOnlyOnce, so the surrounding message content identifies the real issue.

Related errors


AI-assisted analysis of facebook/lexical@76a22dcba9 (2026-08-31). Data as JSON: /api/errors/9d1701e0e94dde53. Report an issue: GitHub.