{"record":{"id":"f6e30b2828e568d3","repo":"angular/components","slug":"svg-tag-not-found","errorCode":null,"errorMessage":"<svg> tag not found","messagePattern":"<svg> tag not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/icon/icon-registry.ts","lineNumber":579,"sourceCode":"    // http://stackoverflow.com/questions/23003278/svg-innerhtml-in-firefox-can-not-display\n    const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));\n    // Clone the node so we don't remove it from the parent icon set element.\n    svg.appendChild(iconElement);\n\n    return this._setSvgAttributes(svg, options);\n  }\n\n  /**\n   * Creates a DOM element from the given SVG string.\n   */\n  private _svgElementFromString(str: TrustedHTML): SVGElement {\n    const div = this._document.createElement('DIV');\n    div.innerHTML = str as unknown as string;\n    const svg = div.querySelector('svg') as SVGElement;\n\n    // TODO: add an ngDevMode check\n    if (!svg) {\n      throw Error('<svg> tag not found');\n    }\n\n    return svg;\n  }\n\n  /**\n   * Converts an element into an SVG node by cloning all of its children.\n   */\n  private _toSvgElement(element: Element): SVGElement {\n    const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));\n    const attributes = element.attributes;\n\n    // Copy over all the attributes from the `symbol` to the new SVG, except the id.\n    for (let i = 0; i < attributes.length; i++) {\n      const {name, value} = attributes[i];\n\n      if (name !== 'id') {\n        svg.setAttribute(name, value);","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/icon/icon-registry.ts#L561-L597","documentation":"MatIconRegistry._svgElementFromString parses an SVG literal string by assigning it to a DIV's innerHTML and querying for an 'svg' element. If the string contains no <svg> tag at its root, the registry cannot produce an icon element and throws. This is a guard against malformed icon literals registered via addSvgIconLiteral or addSvgIconLiteralInNamespace.","triggerScenarios":"Calling registry.addSvgIconLiteral(name, html) or addSvgIconLiteralInNamespace(ns, name, html) with a string whose root is not an <svg> element (e.g. a <path>, <img>, empty string, or HTML wrapper).","commonSituations":"Copying an SVG path's inner markup instead of the whole <svg>...</svg> element; build pipelines that strip the svg tag; passing an asset URL string instead of inline SVG markup.","solutions":["Wrap the literal in a root <svg> element including the xmlns attribute: <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"...\">...</svg>","Verify the string actually contains '<svg' before registering (log it in dev).","If you meant to load from a URL/file, use addSvgIcon(name, sanitizer.bypassSecurityTrustResourceUrl(url)) instead of the literal variant."],"exampleFix":"// before\nregistry.addSvgIconLiteral('star', '<path d=\"M3 3h18v18H3z\"/>');\n// after\nregistry.addSvgIconLiteral('star', '<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M3 3h18v18H3z\"/></svg>');","handlingStrategy":"validation","validationCode":"function isSvgLiteral(str: string): boolean {\n  return typeof str === 'string' && /<svg[\\s>]/i.test(str.trim());\n}\nif (!isSvgLiteral(svgMarkup)) {\n  throw new Error('Icon literal must contain a root <svg> element');\n}\nregistry.addSvgIconLiteral('star', svgMarkup);","typeGuard":"function hasRootSvg(str: unknown): str is string {\n  return typeof str === 'string' && new DOMParser()\n    .parseFromString(str, 'image/svg+xml')\n    .querySelector('svg') !== null;\n}","tryCatchPattern":"try {\n  registry.addSvgIconLiteral(name, markup);\n} catch (e) {\n  if ((e as Error).message.includes('<svg> tag not found')) {\n    console.warn(`Skipping icon \"${name}\": markup has no <svg> root`);\n  } else { throw e; }\n}","preventionTips":["Always copy the full <svg>...</svg> element, never just its inner markup","Include xmlns=\"http://www.w3.org/2000/svg\" on the root svg tag","Add a build-time lint/unit test asserting every registered literal starts with <svg"],"tags":["angular-material","svg","icon-registry"],"backgroundTag":"svg-tag-missing","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}