refactor: SectionFactory static registry, remove dynamic imports
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export type { SectionFactoryProps } from './ui/SectionFactory/SectionFactory';
|
||||
export { SectionFactory } from './ui/SectionFactory/SectionFactory';
|
||||
@@ -1,15 +1,10 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
/**
|
||||
* Registry of dynamic section widgets.
|
||||
*/
|
||||
const SECTIONS: Record<string, () => Promise<{ default: React.ComponentType<Record<string, unknown>> }>> = {
|
||||
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<string, ComponentType<any>> = {
|
||||
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 <SectionComponent />;
|
||||
return <Component />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user