Files
school_compare/nextjs-app/app/page.tsx
Tudor b3fc55faf6
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 34s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m12s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
Fix: Await searchParams in home page for Next.js 15 compatibility
In Next.js 15, searchParams is a Promise that must be awaited before
accessing its properties. The home page was directly accessing
searchParams.search, searchParams.local_authority, etc., which resulted
in all parameters being undefined. This caused all API calls to return
all schools regardless of search/filter parameters.

This fix brings the home page in line with the compare and rankings
pages, which already correctly await searchParams.

Fixes search, filter, and pagination functionality on the home page.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 22:09:17 +00:00

69 lines
1.8 KiB
TypeScript

/**
* Home Page (SSR)
* Main landing page with school search and browsing
*/
import { fetchSchools, fetchFilters } from '@/lib/api';
import { HomeView } from '@/components/HomeView';
interface HomePageProps {
searchParams: Promise<{
search?: string;
local_authority?: string;
school_type?: string;
page?: string;
postcode?: string;
radius?: string;
}>;
}
export const metadata = {
title: 'Home',
description: 'Search and compare primary school KS2 performance across England',
};
// Force dynamic rendering (no static generation at build time)
export const dynamic = 'force-dynamic';
export default async function HomePage({ searchParams }: HomePageProps) {
// Await search params (Next.js 15 requirement)
const params = await searchParams;
// Parse search params
const page = parseInt(params.page || '1');
const radius = params.radius ? parseInt(params.radius) : undefined;
// Fetch data on server with error handling
try {
const [schoolsData, filtersData] = await Promise.all([
fetchSchools({
search: params.search,
local_authority: params.local_authority,
school_type: params.school_type,
postcode: params.postcode,
radius,
page,
page_size: 50,
}),
fetchFilters(),
]);
return (
<HomeView
initialSchools={schoolsData}
filters={filtersData || { local_authorities: [], school_types: [], years: [] }}
/>
);
} catch (error) {
console.error('Error fetching data for home page:', error);
// Return error state with empty data
return (
<HomeView
initialSchools={{ schools: [], page: 1, page_size: 50, total: 0, total_pages: 0 }}
filters={{ local_authorities: [], school_types: [], years: [] }}
/>
);
}
}