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
- Read the actual `message` argument logged alongside — it carries the real diagnostic; fix whatever condition that message describes.
- If it is your own code, ensure warnOnlyOnce is only called with a fully descriptive message since it is the user's only signal.
- 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
- Always pass a fully descriptive message — the logged text is the only signal the user gets.
- Remember the returned function warns only once per instance; create a new instance per distinct issue.
- Treat the warning it emits as actionable, not noise.
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
- [lexical] duplicate DOMImportRule name "${rule.name}" — keep
- TableNode: hasHorizontalScroll is active but theme.tableScro
- ${name} must implement static "${method}" method
- ${name} should implement "importJSON" method to ensure JSON
- When using "display: flex" or "display: inline-flex" on an e
AI-assisted analysis of facebook/lexical@76a22dcba9 (2026-08-31).
Data as JSON: /api/errors/9d1701e0e94dde53.
Report an issue: GitHub.