{"record":{"id":"b4b914e167c02aaa","repo":"mui/material-ui","slug":"expected-a-single-child-of-the-root","errorCode":null,"errorMessage":"Expected a single child of the root","messagePattern":"Expected a single child of the root","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mui-icons-material/builder.mjs","lineNumber":148,"sourceCode":"      { name: 'removeStyleElement' },\n      { name: 'removeScripts' },\n      { name: 'removeEmptyContainers' },\n    ],\n  });\n\n  // True if the svg has multiple children\n  let childrenAsArray = false;\n  const jsxResult = svgo.optimize(result.data, {\n    plugins: [\n      {\n        name: 'svgAsReactFragment',\n        fn: () => {\n          return {\n            root: {\n              enter(root) {\n                const [svg, ...rootChildren] = root.children;\n                if (rootChildren.length > 0) {\n                  throw new Error('Expected a single child of the root');\n                }\n                if (svg.type !== 'element' || svg.name !== 'svg') {\n                  throw new Error('Expected an svg element as the root child');\n                }\n\n                if (svg.children.length > 1) {\n                  childrenAsArray = true;\n                  svg.children.forEach((svgChild, index) => {\n                    svgChild.attributes.key = index;\n                    // Original name will be restored later\n                    // We just need a mechanism to convert the resulting\n                    // svg string into an array of JSX elements\n                    svgChild.name = `SVGChild:${svgChild.name}`;\n                  });\n                }\n\n                root.children = svg.children;\n              },","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/mui/material-ui/blob/bdc96df2cb530fcdd60a7a7aabe37f610ce0f0a5/packages/mui-icons-material/builder.mjs#L130-L166","documentation":"In the @mui/icons-material builder, an SVGO plugin (svgAsReactFragment) inspects the optimised SVG and asserts the document root has exactly one child. If the optimised SVG contains more than one top-level element (e.g. trailing whitespace nodes become elements, or two <svg> roots), the build throws. The generated icon component assumes a single <svg> root fragment child.","triggerScenarios":"Running the icon build/generator over an SVG source whose root has multiple element children after SVGO optimisation; corrupted/hand-edited SVG sources; an SVGO plugin config change that produces extra root nodes.","commonSituations":"Adding a new custom icon whose source SVG was concatenated from multiple fragments; SVGO version bump changing how comments/whitespace are preserved at the root.","solutions":["Open the offending SVG in an editor and ensure it has a single <svg>...</svg> root with nothing outside it (no comments, text, or second root).","Re-run the SVGO optimisation manually to inspect the post-optimisation output before feeding it to the builder.","If the source is generated by download.mjs, re-download the icon and check the upstream gstatic SVG."],"exampleFix":"<!-- before: two roots -->\n<svg>...</svg>\n<svg>...</svg>\n<!-- after -->\n<svg>...</svg>","handlingStrategy":"validation","validationCode":"import { parse } from 'svg-parser';\nfunction hasSingleRootChild(svgString) {\n  const ast = parse(svgString);\n  const root = ast.children.filter(c => c.type === 'root')[0];\n  return root.children.filter(c => c.type !== 'text' || c.value.trim().length > 0).length === 1;\n}\n// run before feeding the SVG to the builder","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint each icon source for a single <svg> root with no siblings before building.","Run SVGO and inspect its output when adding new icons.","Keep icon sources machine-generated (e.g. from a vector tool's SVG export)."],"tags":["build","icons","svg","tooling","validation"],"backgroundTag":null,"analyzedSha":"bdc96df2cb530fcdd60a7a7aabe37f610ce0f0a5","analyzedAt":"2026-08-12T22:59:56.717Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}