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';
|
import { notFound } from 'next/navigation';
|
||||||
|
import type { ComponentType } from 'react';
|
||||||
/**
|
import BioSection from '../../../BioSection/ui/BioSection/BioSection';
|
||||||
* Registry of dynamic section widgets.
|
import ExperienceSection from '../../../ExperienceSection/ui/ExperienceSection/ExperienceSection';
|
||||||
*/
|
import IntroSection from '../../../IntroSection/ui/IntroSection/IntroSection';
|
||||||
const SECTIONS: Record<string, () => Promise<{ default: React.ComponentType<Record<string, unknown>> }>> = {
|
import ProjectsSection from '../../../ProjectsSection/ui/ProjectsSection/ProjectsSection';
|
||||||
intro: () => import('../../../IntroSection/ui/IntroSection/IntroSection'),
|
import SkillsSection from '../../../SkillsSection/ui/SkillsSection/SkillsSection';
|
||||||
bio: () => import('../../../BioSection/ui/BioSection/BioSection'),
|
|
||||||
skills: () => import('../../../SkillsSection/ui/SkillsSection/SkillsSection'),
|
|
||||||
experience: () => import('../../../ExperienceSection/ui/ExperienceSection/ExperienceSection'),
|
|
||||||
projects: () => import('../../../ProjectsSection/ui/ProjectsSection/ProjectsSection'),
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Props for the SectionFactory widget.
|
* Props for the SectionFactory widget.
|
||||||
@@ -21,18 +16,25 @@ export type SectionFactoryProps = {
|
|||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// biome-ignore lint/suspicious/noExplicitAny: registry holds heterogeneous RSC components
|
||||||
* Factory widget that dynamically imports and renders the correct section widget.
|
const SECTIONS: Record<string, ComponentType<any>> = {
|
||||||
* Based on the provided slug.
|
intro: IntroSection,
|
||||||
*/
|
bio: BioSection,
|
||||||
export async function SectionFactory({ slug }: SectionFactoryProps) {
|
skills: SkillsSection,
|
||||||
const loadSection = SECTIONS[slug];
|
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();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { default: SectionComponent } = await loadSection();
|
return <Component />;
|
||||||
|
|
||||||
return <SectionComponent />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user