{"record":{"id":"b89c3e5b73fcf421","repo":"facebook/lexical","slug":"unrecognized-charset","errorCode":null,"errorMessage":"Unrecognized charset","messagePattern":"Unrecognized charset","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/lexical-react/src/LexicalCharacterLimitPlugin.tsx","lineNumber":91,"sourceCode":"    remainingCharacters,\n  }: {\n    remainingCharacters: number;\n  }) => JSX.Element;\n}): JSX.Element {\n  const [editor] = useLexicalComposerContext();\n\n  const [remainingCharacters, setRemainingCharacters] = useState(maxLength);\n\n  const characterLimitProps = useMemo(\n    () => ({\n      remainingCharacters: setRemainingCharacters,\n      strlen: (text: string) => {\n        if (charset === 'UTF-8') {\n          return utf8Length(text);\n        } else if (charset === 'UTF-16') {\n          return text.length;\n        } else {\n          throw new Error('Unrecognized charset');\n        }\n      },\n    }),\n    [charset],\n  );\n\n  useCharacterLimit(editor, maxLength, characterLimitProps);\n\n  return renderer({remainingCharacters});\n}\n","sourceCodeStart":73,"sourceCodeEnd":102,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical-react/src/LexicalCharacterLimitPlugin.tsx#L73-L102","documentation":"LexicalCharacterLimitPlugin computes the current text length using a charset-dependent strlen function. Only 'UTF-8' (byte-length counting via utf8Length) and 'UTF-16' (JS string length) are supported; passing any other charset value makes the memoized strlen throw 'Unrecognized charset'.","triggerScenarios":"Rendering <CharacterLimitPlugin charset=\"...\" /> with a charset value other than the string 'UTF-8' or 'UTF-16' — e.g. 'utf-8' (lowercase), 'ASCII', undefined, or a typo like 'UTF8'.","commonSituations":"Passing lowercase 'utf-8' from a config value; assuming 'UTF8' (no hyphen) is valid; feeding charset from an enum defined elsewhere with unsupported values; leaving charset undefined expecting a default.","solutions":["Pass charset='UTF-8' or charset='UTF-16' exactly (case-sensitive, with hyphen).","Normalize any external config value to one of the two supported strings before rendering.","If you need another encoding, supply the counting logic yourself or omit the plugin and compute limits manually.","Check the plugin's prop types (charset?: 'UTF-8' | 'UTF-16') to catch invalid values at compile time."],"exampleFix":"// before\n<CharacterLimitPlugin charset=\"utf-8\" maxLength={280} />\n// after\n<CharacterLimitPlugin charset=\"UTF-8\" maxLength={280} />","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set(['UTF-8', 'UTF-16']);\nif (!SUPPORTED.has(charset)) {\n  throw new Error(`charset must be 'UTF-8' or 'UTF-16', got ${charset}`);\n}","typeGuard":"function isSupportedCharset(c: unknown): c is 'UTF-8' | 'UTF-16' {\n  return c === 'UTF-8' || c === 'UTF-16';\n}","tryCatchPattern":"let strlen: (text: string) => number;\ntry {\n  strlen = computeStrlen(charset);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Unrecognized charset') {\n    strlen = (t) => t.length; // fallback to UTF-16 semantics\n  } else { throw e; }\n}","preventionTips":["Use the exact strings 'UTF-8'/'UTF-16'.","Type the prop as 'UTF-8' | 'UTF-16' so TS rejects invalid values.","Normalize config-driven charset values with a whitelist map."],"tags":["react","plugin","configuration","encoding"],"backgroundTag":"unrecognized-charset","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}