-
-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds nextjs specific dynamic import map #2030
base: main
Are you sure you want to change the base?
Conversation
On further inspection, would it make sense to publish this map as a separate |
Hmm, yess, we shouldn't have |
Agreed. Please let me know how I can help in here. RN we have it hard coded in our open source repo but it make sense as you said to have it generated on install. |
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Not stale, we need this PR because the issue hasn't been solved yet. |
Hi @zomars |
@michaelschufi been banging my head against the wall wondering why my development server was sooooo slow until I found this of this thread and this one (#1576). Definitely feel like this needs more attention either by way of a fix, or improved documentation on best practices. Sharing my current workaround for now below... import { type LucideProps, icons } from 'lucide-react';
type IconComponentName = keyof typeof icons;
interface IconProps extends LucideProps {
name: string; // because this is coming from the CMS
}
// 👮♀️ guard
function isValidIconComponent(componentName: string): componentName is IconComponentName {
return componentName in icons;
}
export function DynamicIcon({ name, ...props }: IconProps) {
// we need to convert kebab-case to PascalCase because we formerly relied on
// lucide-react/dynamicIconImports and the icon names (not the component names) are what are stored in the CMS.
const kebabToPascal = (str: string) =>
str
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join('');
const componentName = kebabToPascal(name);
// ensure what is in the CMS is a valid icon component
if (!isValidIconComponent(componentName)) {
return null;
}
// lucide-react/dynamicIconImports makes makes NextJS development server very slow
// https://github.com/lucide-icons/lucide/issues/1576
const Icon = icons[componentName];
return <Icon {...props} />;
} |
closes #1725 #1576
What is the purpose of this pull request?
Description
As specified by the Next.js team we should not use
dynamic
inside a React component. This uses the recommended approach with a map with dynamic imports.Before Submitting