Skip to content

Commit

Permalink
fix(template): avoid rendering undefined SVG content
Browse files Browse the repository at this point in the history
Fixes #191
  • Loading branch information
metonym committed Sep 30, 2024
1 parent 36abcbe commit 75c04e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/build-info.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ export const template = ({ descriptor }: IconOutput) => `<script>
{...attributes}
{...$$restProps}>
{#if title}<title>{title}</title>{/if}
${descriptor?.content?.map((element) => toString(element)).join("")}
${(descriptor?.content ?? []).map((element) => toString(element)).join("")}
</svg>`;

export const templateSvg = ({ moduleName, descriptor }: IconOutput) => {
const isGlyph = /Glyph$/.test(moduleName);
const { width, height, ...rest } = descriptor?.attrs;
const content = descriptor?.content ?? [];

if (!descriptor?.content) {
console.error(`No content found for ${moduleName}`);
if (!content) {
console.error(`No content found for ${moduleName}`, descriptor);
}

let attrs = formatAttributes(
Expand All @@ -45,6 +46,6 @@ export const templateSvg = ({ moduleName, descriptor }: IconOutput) => {
${attrs}
fill="currentColor"
preserveAspectRatio="xMidYMid meet">
${descriptor?.content?.map((element) => toString(element)).join("")}
${content.map((element) => toString(element)).join("")}
</svg>`;
};

0 comments on commit 75c04e0

Please sign in to comment.