{"record":{"id":"3535a0277c3aab52","repo":"facebook/react","slug":"tag-is-a-self-closing-tag-and-must-neither-have","errorCode":null,"errorMessage":"${tag} is a self-closing tag and must neither have `children` nor use `dangerouslySetInnerHTML`.","messagePattern":"(.+?) is a self-closing tag and must neither have `children` nor use `dangerouslySetInnerHTML`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js","lineNumber":3547,"sourceCode":"\nfunction pushSelfClosing(\n  target: Array<Chunk | PrecomputedChunk>,\n  props: Object,\n  tag: string,\n  formatContext: FormatContext,\n): null {\n  target.push(startChunkForTag(tag));\n\n  for (const propKey in props) {\n    if (hasOwnProperty.call(props, propKey)) {\n      const propValue = props[propKey];\n      if (propValue == null) {\n        continue;\n      }\n      switch (propKey) {\n        case 'children':\n        case 'dangerouslySetInnerHTML':\n          throw new Error(\n            `${tag} is a self-closing tag and must neither have \\`children\\` nor ` +\n              'use `dangerouslySetInnerHTML`.',\n          );\n        default:\n          pushAttribute(target, propKey, propValue);\n          break;\n      }\n    }\n  }\n\n  pushViewTransitionAttributes(target, formatContext);\n\n  target.push(endOfStartTagSelfClosing);\n  return null;\n}\n\nfunction pushStartMenuItem(\n  target: Array<Chunk | PrecomputedChunk>,","sourceCodeStart":3529,"sourceCodeEnd":3565,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js#L3529-L3565","documentation":"Thrown by the generic pushSelfClosing helper (message interpolates the actual tag name) when one of the void elements it serves — base, area, br, col, embed, hr, keygen, param, source, track, wbr (this helper also serializes meta and img through their own paths) — receives a non-null children or dangerouslySetInnerHTML prop. These tags have no end tag in HTML, so any children would be parsed as siblings and corrupt the document; React aborts instead.","triggerScenarios":"JSX like <br>spacing</br>, <hr {...props} /> where props contains children, <source src={v}>{label}</source>, <col>{header}</col>, or any void element receiving children via prop spread.","commonSituations":"Generic HTML-emitting components that spread user props onto arbitrary tags; HTML-to-JSX converters producing closed void tags with content; copy-paste from non-strict templates; children leaking through {...rest} in table/part components (col, source in picture, track in video).","solutions":["Self-close the element and remove its children entirely","Strip children before spreading props onto void elements: const {children, ...rest} = props","If content was intended, move it to a sibling element instead of inside the void tag"],"exampleFix":"// before\n<br></br>\n<hr {...props} /> {/* props.children present */}\n\n// after\n<br />\nconst {children, ...rest} = props;\n<hr {...rest} />","handlingStrategy":"type-guard","validationCode":"const VOID = new Set(['base','area','br','col','embed','hr','keygen','param','source','track','wbr','meta','link','img','input']);\nfunction safeTagProps(tag: string, props: Record<string, unknown>) {\n  if (VOID.has(tag)) {\n    const {children, dangerouslySetInnerHTML, ...rest} = props as any;\n    return rest;\n  }\n  return props;\n}","typeGuard":"type VoidElementProps = {children?: never; dangerouslySetInnerHTML?: never};","tryCatchPattern":null,"preventionTips":["Never put children inside void elements (br, hr, source, col, track, ...)","When spreading arbitrary props onto dynamic tags, filter children for known void tags","Rely on JSX typings for intrinsic void elements in TypeScript"],"tags":["ssr","void-element","children","dangerouslysetinnerhtml","br","source"],"backgroundTag":"void-element-children","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}