Skip to content

Commit

Permalink
fix: 500 errors if an icon cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlustra committed Jun 29, 2021
1 parent 9207500 commit 0a59ea7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions icongenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const TO_FOLDER = `./client/components/icons`;

const location = `./node_modules/`;
const package = "@react-icons/all-files";
const pkg = "@react-icons/all-files";

try {
console.warn("CLEANING ICON FILES...");
Expand Down Expand Up @@ -79,19 +79,20 @@ const iconPacks = iconPackNames.map((dir) => {
(acc, file) => {
const fileName = file.split(".d.ts")[0];
return `${acc}
${fileName}: dynamic(() => import("${package}/${dir}/${fileName}").then(mod => mod.${fileName})),`;
${fileName}: dynamic(() => import("${pkg}/${dir}/${fileName}").then(mod => mod.${fileName})),`;
},
`
import type { IconBaseProps } from "@react-icons/all-files";
import dynamic from "next/dynamic";
import React, { ComponentType } from "react";
import { FiAlertTriangle } from "@react-icons/all-files/fi/FiAlertTriangle";
export interface IconPackProps extends IconBaseProps {
icon: string;
}
export const IconPack: React.FC<IconPackProps> = ({ icon, ...props }) => {
const Icon = dynamicIcons[icon];
const Icon = dynamicIcons[icon] ?? ((props: IconPackProps) => <FiAlertTriangle {...props} />);
return <Icon {...props} />;
};
Expand Down Expand Up @@ -120,6 +121,7 @@ const indexFileContent =
},
`import dynamic from "next/dynamic";
import type { IconBaseProps } from "@react-icons/all-files";
import { FiAlertTriangle } from "@react-icons/all-files/fi/FiAlertTriangle";
import React from "react";
Expand All @@ -129,7 +131,7 @@ export interface DynamicIconProps extends IconBaseProps {
}
export const DynamicIcon: React.FC<DynamicIconProps> = ({ iconPack, ...props }) => {
const IconPack = dynamicIconPacks[iconPack];
const IconPack = dynamicIconPacks[iconPack] ?? ((props: DynamicIconProps) => <FiAlertTriangle {...props} />);
return <IconPack {...props} />;
};
Expand Down

0 comments on commit 0a59ea7

Please sign in to comment.