feat(perf,seo): enable react strict mode, prefetch projects & services on server, and expand vitest coverage
Deploy Frontend / deploy (push) Successful in 1m22s
Deploy Frontend / deploy (push) Successful in 1m22s
This commit is contained in:
1 parent
ed65617433
commit
7ba29d290f
6 files changed
+122
-15
No files matched your search
+1
-1
@@ -4,7 +4,7 @@ import withBundleAnalyzer from '@next/bundle-analyzer';
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: 'standalone',
|
||||
reactStrictMode: false,
|
||||
reactStrictMode: true,
|
||||
poweredByHeader: false,
|
||||
turbopack: {},
|
||||
// Server Actions reject request bodies over 1 MB by default, which is smaller than
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import Projects from '@/app/(routes)/(website)/components/projects/projects';
|
||||
import { Project } from '@/app/types/types';
|
||||
|
||||
const mockDict = {
|
||||
website: {
|
||||
homePage: {
|
||||
projects: {
|
||||
title: 'پروژههای شاخص',
|
||||
description: 'معماری و توسعه سامانهها',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockProjects: Project[] = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'سوپراپ بانکی صاپ',
|
||||
description: 'توسعه و نگهداری سرویسهای شتابی',
|
||||
category: 'Enterprise & FinTech',
|
||||
category_id: 1,
|
||||
images: [{ src: '/images/project1.png', zIndex: 1 }],
|
||||
},
|
||||
];
|
||||
|
||||
describe('Projects Component', () => {
|
||||
it('renders section title and description from dict', () => {
|
||||
render(<Projects dict={mockDict} />);
|
||||
expect(screen.getByText('پروژههای شاخص')).toBeInTheDocument();
|
||||
expect(screen.getByText('معماری و توسعه سامانهها')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders initial projects immediately without loading skeletons', () => {
|
||||
render(<Projects dict={mockDict} initialProjects={mockProjects} />);
|
||||
expect(screen.getByText('سوپراپ بانکی صاپ')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { ThemeToggle } from '@/app/(routes)/(website)/components/theme-toggle/theme-toggle';
|
||||
|
||||
vi.mock('next-themes', () => ({
|
||||
useTheme: () => ({
|
||||
theme: 'dark',
|
||||
setTheme: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('ThemeToggle Component', () => {
|
||||
it('renders theme toggle button with accessibility attributes', () => {
|
||||
render(<ThemeToggle />);
|
||||
const button = screen.getByRole('button', { name: /toggle theme/i });
|
||||
expect(button).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -28,15 +28,48 @@ export const metadata: Metadata = {
|
||||
},
|
||||
};
|
||||
|
||||
async function getInitialShowcaseData(locale: string) {
|
||||
const backend = process.env.NEXT_PUBLIC_BACK_URL || "https://backend.parsaaghayi.ir";
|
||||
try {
|
||||
const [servicesRes, projectsRes] = await Promise.all([
|
||||
fetch(`${backend}/api/website/services/${locale}`, { next: { revalidate: 300 } }),
|
||||
fetch(
|
||||
`${backend}/api/website/projects/translation/${locale}?sort=desc&per_page=40`,
|
||||
{ next: { revalidate: 300 } },
|
||||
),
|
||||
]);
|
||||
|
||||
const services = servicesRes.ok ? await servicesRes.json() : [];
|
||||
const projectsData = projectsRes.ok ? await projectsRes.json() : {};
|
||||
|
||||
return {
|
||||
services: Array.isArray(services) ? services : [],
|
||||
projects: projectsData?.projects?.data || [],
|
||||
categories: projectsData?.categories || [],
|
||||
};
|
||||
} catch {
|
||||
return { services: [], projects: [], categories: [] };
|
||||
}
|
||||
}
|
||||
|
||||
export default async function Home() {
|
||||
const dict = await getDictionary(await getDefaultLocale());
|
||||
const locale = await getDefaultLocale();
|
||||
const [dict, initialData] = await Promise.all([
|
||||
getDictionary(locale),
|
||||
getInitialShowcaseData(locale),
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="mesh-gradient min-h-screen w-full flex flex-col items-center">
|
||||
<div className="flex w-full max-w-[1420px] flex-col items-center gap-[100px] py-20 px-6">
|
||||
<Hero dict={dict} />
|
||||
<AboutMe />
|
||||
<Services dict={dict} />
|
||||
<MyProjects dict={dict} />
|
||||
<Services dict={dict} initialServices={initialData.services} />
|
||||
<MyProjects
|
||||
dict={dict}
|
||||
initialProjects={initialData.projects}
|
||||
initialCategories={initialData.categories}
|
||||
/>
|
||||
<Testimonials dict={dict} />
|
||||
<Contact dict={dict} />
|
||||
</div>
|
||||
|
||||
@@ -26,6 +26,8 @@ interface MyProjectsProps {
|
||||
};
|
||||
};
|
||||
};
|
||||
initialProjects?: Project[];
|
||||
initialCategories?: CategoryResponse[];
|
||||
}
|
||||
|
||||
const MAX_PROJECTS = 6;
|
||||
@@ -35,17 +37,31 @@ const NEWEST_KEY = "newest";
|
||||
const UNCATEGORIZED_KEY = "uncategorized";
|
||||
const categoryKey = (id: number) => `category-${id}`;
|
||||
|
||||
export default function Projects({ dict }: MyProjectsProps) {
|
||||
const [categories, setCategories] = useState<ProjectCategory[]>([]);
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
// The selected tab is a stable category key, not a translated label.
|
||||
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selectedProject, setSelectedProject] = useState<Project | null>(null);
|
||||
export default function Projects({
|
||||
dict,
|
||||
initialProjects = [],
|
||||
initialCategories = [],
|
||||
}: MyProjectsProps) {
|
||||
const locale = resolveLocale();
|
||||
const isRTL = locale === "fa";
|
||||
const newestLabel = isRTL ? "جدیدترینها" : "Newest";
|
||||
|
||||
const newestLabel = locale === "fa" ? "جدیدترینها" : "Newest";
|
||||
const buildCategoryList = (cats: CategoryResponse[]) => [
|
||||
{ key: NEWEST_KEY, id: null, label: newestLabel },
|
||||
...cats.slice(0, MAX_CATEGORIES).map((c) => ({
|
||||
key: categoryKey(c.id),
|
||||
id: c.id,
|
||||
label: c.title,
|
||||
})),
|
||||
];
|
||||
|
||||
const [categories, setCategories] = useState<ProjectCategory[]>(() =>
|
||||
buildCategoryList(initialCategories),
|
||||
);
|
||||
const [projects, setProjects] = useState<Project[]>(initialProjects);
|
||||
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(initialProjects.length === 0);
|
||||
const [selectedProject, setSelectedProject] = useState<Project | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProjects = async () => {
|
||||
|
||||
@@ -19,11 +19,12 @@ interface ServicesProps {
|
||||
};
|
||||
};
|
||||
};
|
||||
initialServices?: Service[];
|
||||
}
|
||||
|
||||
export default function Services({ dict }: ServicesProps) {
|
||||
const [services, setServices] = useState<Service[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
export default function Services({ dict, initialServices = [] }: ServicesProps) {
|
||||
const [services, setServices] = useState<Service[]>(initialServices);
|
||||
const [loading, setLoading] = useState(initialServices.length === 0);
|
||||
const locale = resolveLocale();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user