From 24bf946cb022e7bf5b1b08448b0e911f7d67809d Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Tue, 5 May 2026 09:41:56 +0300 Subject: [PATCH] refactor: SectionFactory static registry, remove dynamic imports --- src/widgets/SectionFactory/index.ts | 2 + .../ui/SectionFactory/SectionFactory.tsx | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 src/widgets/SectionFactory/index.ts diff --git a/src/widgets/SectionFactory/index.ts b/src/widgets/SectionFactory/index.ts new file mode 100644 index 0000000..4a2bd6b --- /dev/null +++ b/src/widgets/SectionFactory/index.ts @@ -0,0 +1,2 @@ +export type { SectionFactoryProps } from './ui/SectionFactory/SectionFactory'; +export { SectionFactory } from './ui/SectionFactory/SectionFactory'; diff --git a/src/widgets/SectionFactory/ui/SectionFactory/SectionFactory.tsx b/src/widgets/SectionFactory/ui/SectionFactory/SectionFactory.tsx index 8c626a4..9bb4892 100644 --- a/src/widgets/SectionFactory/ui/SectionFactory/SectionFactory.tsx +++ b/src/widgets/SectionFactory/ui/SectionFactory/SectionFactory.tsx @@ -1,15 +1,10 @@ import { notFound } from 'next/navigation'; - -/** - * Registry of dynamic section widgets. - */ -const SECTIONS: Record Promise<{ default: React.ComponentType> }>> = { - intro: () => import('../../../IntroSection/ui/IntroSection/IntroSection'), - bio: () => import('../../../BioSection/ui/BioSection/BioSection'), - skills: () => import('../../../SkillsSection/ui/SkillsSection/SkillsSection'), - experience: () => import('../../../ExperienceSection/ui/ExperienceSection/ExperienceSection'), - projects: () => import('../../../ProjectsSection/ui/ProjectsSection/ProjectsSection'), -}; +import type { ComponentType } from 'react'; +import BioSection from '../../../BioSection/ui/BioSection/BioSection'; +import ExperienceSection from '../../../ExperienceSection/ui/ExperienceSection/ExperienceSection'; +import IntroSection from '../../../IntroSection/ui/IntroSection/IntroSection'; +import ProjectsSection from '../../../ProjectsSection/ui/ProjectsSection/ProjectsSection'; +import SkillsSection from '../../../SkillsSection/ui/SkillsSection/SkillsSection'; /** * Props for the SectionFactory widget. @@ -21,18 +16,25 @@ export type SectionFactoryProps = { slug: string; }; -/** - * Factory widget that dynamically imports and renders the correct section widget. - * Based on the provided slug. - */ -export async function SectionFactory({ slug }: SectionFactoryProps) { - const loadSection = SECTIONS[slug]; +// biome-ignore lint/suspicious/noExplicitAny: registry holds heterogeneous RSC components +const SECTIONS: Record> = { + intro: IntroSection, + bio: BioSection, + skills: SkillsSection, + experience: ExperienceSection, + projects: ProjectsSection, +}; - if (!loadSection) { +/** + * Renders the correct section widget for a given slug. + * Uses a static registry — React resolves async RSC children internally. + */ +export function SectionFactory({ slug }: SectionFactoryProps) { + const Component = SECTIONS[slug]; + + if (!Component) { notFound(); } - const { default: SectionComponent } = await loadSection(); - - return ; + return ; }