Files
lucide/packages/shared/src/utils/mergeClasses.ts
T
Claude f8d0e11faf perf(lucide-react): cache static icon work and speed up rendering
- Icon: build class names, view box and child elements once per icon
  data instead of on every render, and build the svg props directly
- Icon: render nested icon nodes, which were dropped before
- createLucideIcon: drop the redundant className destructuring
- DynamicIcon: remember loaded icon data so an icon that was loaded
  before renders right away, without the fallback
- shared: cheaper mergeClasses and buildLucideIconNode with identical
  output
- add a render benchmark (pnpm bench)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G9u8Fgx7hqgYx7gfUQgfY6
2026-11-10 22:50:10 +00:00

22 lines
517 B
TypeScript

/**
* Merges classes into a single string
*
* @param {array} classes
* @returns {string} A string of classes
*/
export const mergeClasses = <ClassType = string | undefined | null>(...classes: ClassType[]) => {
const uniqueClasses: ClassType[] = [];
for (const className of classes) {
if (
Boolean(className) &&
(className as string).trim() !== '' &&
!uniqueClasses.includes(className)
) {
uniqueClasses.push(className);
}
}
return uniqueClasses.join(' ').trim();
};