Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.0 KB
Raw Blame
import type {
  ModelIcon as LobeModelIcon,
  ModelTag as LobeModelTag,
  ProviderCombine as LobeProviderCombine,
  ProviderIcon as LobeProviderIcon,
} from '@lobehub/icons';
import { Skeleton } from '@lobehub/ui';
import type { ComponentProps } from 'react';
import { lazy, Suspense } from 'react';

// The catalog-backed features of @lobehub/icons statically import every brand
// icon (~3 MB). Mounting them through lazy() keeps that catalog in one shared
// chunk that loads after paint instead of inside each route's closure.
const LazyModelIcon = lazy(() =>
  import('@/libs/modelIcon').then(({ ModelIcon }) => ({ default: ModelIcon })),
);
const LazyModelTag = lazy(() =>
  import('@/libs/modelIcon').then(({ ModelTag }) => ({ default: ModelTag })),
);
const LazyProviderIcon = lazy(() =>
  import('@/libs/providerIcon').then(({ ProviderIcon }) => ({ default: ProviderIcon })),
);
const LazyProviderCombine = lazy(() =>
  import('@/libs/providerIcon').then(({ ProviderCombine }) => ({ default: ProviderCombine })),
);

const DEFAULT_SIZE = 24;

export const ModelIcon = (props: ComponentProps<typeof LobeModelIcon>) => {
  const size = props.size ?? DEFAULT_SIZE;
  return (
    <Suspense fallback={<Skeleton height={size} width={size} />}>
      <LazyModelIcon {...props} />
    </Suspense>
  );
};

export const ProviderIcon = (props: ComponentProps<typeof LobeProviderIcon>) => {
  const size = props.size ?? DEFAULT_SIZE;
  return (
    <Suspense fallback={<Skeleton height={size} width={size} />}>
      <LazyProviderIcon {...props} />
    </Suspense>
  );
};

export const ModelTag = (props: ComponentProps<typeof LobeModelTag>) => (
  <Suspense fallback={<Skeleton height={22} width={96} />}>
    <LazyModelTag {...props} />
  </Suspense>
);

export const ProviderCombine = (props: ComponentProps<typeof LobeProviderCombine>) => {
  const size = props.size ?? DEFAULT_SIZE;
  return (
    <Suspense fallback={<Skeleton height={size} width={size * 4} />}>
      <LazyProviderCombine {...props} />
    </Suspense>
  );
};