{"record":{"id":"9d1701e0e94dde53","repo":"facebook/lexical","slug":"message","errorCode":null,"errorMessage":"message","messagePattern":"message","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"packages/lexical-internal/src/warnOnlyOnce.ts","lineNumber":17,"sourceCode":"/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nconst __DEV__ = process.env.NODE_ENV !== 'production';\n\n/*@__INLINE__*/\nexport default function warnOnlyOnce(message: string): () => void {\n  if (__DEV__) {\n    let run = false;\n    return () => {\n      if (!run) {\n        console.warn(message);\n      }\n      run = true;\n    };\n  } else {\n    return () => {};\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical-internal/src/warnOnlyOnce.ts#L1-L25","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst warn = warnOnlyOnce('');\nwarn();\n// after\nconst warn = warnOnlyOnce('Lexical: deprecated $foo() used; migrate to $bar()');\nwarn(); // logs once","handlingStrategy":"validation","validationCode":"if (typeof message !== 'string' || message.length === 0) throw new Error('warnOnlyOnce requires a descriptive message');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["console-warning","dev-only","once","utility"],"backgroundTag":"deprecated-api-usage","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}