Skip to content

Commit

Permalink
fix: do not throw error when no sprites are found
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Moore committed Apr 5, 2022
1 parent b2d4bb8 commit 3b29d89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-pots-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-icon": patch
---

Improve warning when no sprites are found rather than throwing an error
10 changes: 7 additions & 3 deletions packages/core/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ export function trackSprite(result: any, name: string) {
}
}

const warned = new Set();
export async function getUsedSprites(result: any) {
if (typeof result[AstroIcon] !== "undefined") {
return Array.from(result[AstroIcon]["sprites"]);
}
throw new Error(
`[astro-icon] <SpriteSheet> should be the very last child of the page's <body>!\nIs it currently placed before any <Sprite> components?`
);
const pathname = result._metadata.pathname;
if (!warned.has(pathname)) {
console.log(`[astro-icon] No sprites found while rendering "${pathname}"`);
warned.add(pathname);
}
return []
}

2 comments on commit 3b29d89

@vercel
Copy link

@vercel vercel bot commented on 3b29d89 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

astroicon – ./packages/www/

astro-icon-www.vercel.app
astroicon-nmoo.vercel.app
astroicon-git-main-nmoo.vercel.app
www.astroicon.dev
astroicon.dev

@vercel
Copy link

@vercel vercel bot commented on 3b29d89 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

api-astroicon – ./packages/service

api-astroicon-nmoo.vercel.app
api.astroicon.dev
api-astroicon-git-main-nmoo.vercel.app

Please sign in to comment.