From bc2133e84efc8530c1a97b60c269a850676b0175 Mon Sep 17 00:00:00 2001 From: lekss361 Date: Mon, 18 May 2026 07:01:44 +0300 Subject: [PATCH] fix(sf-fe): decode cad URL param in Server Component (B5 400 regression) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend /api/v1/parcels/{cad}/analyze rejects URL-encoded cad with HTTP 400. PR #351 originally fixed by decoding params.cad in the Client Component. A7 split (PR #356) refactored into Server Component + AnalysisPageContent and forgot to carry the decode forward — every analysis page request through cad URL bar (e.g. /site-finder/analysis/66%3A41%3A0204016%3A10) now passes the encoded form to the hooks, which encodeURIComponent again, producing %253A, which FastAPI decodes once to %3A, which the regex rejects. Fix: decodeURIComponent(cadRaw) at the Server Component boundary (page.tsx) in both generateMetadata and the page export. Downstream sees canonical '66:41:0204016:10' and re-encodes exactly once when building API URLs. --- frontend/src/app/site-finder/analysis/[cad]/page.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/site-finder/analysis/[cad]/page.tsx b/frontend/src/app/site-finder/analysis/[cad]/page.tsx index c3c8a854..6a82c8da 100644 --- a/frontend/src/app/site-finder/analysis/[cad]/page.tsx +++ b/frontend/src/app/site-finder/analysis/[cad]/page.tsx @@ -9,10 +9,17 @@ interface PageProps { params: Promise<{ cad: string }>; } +// Next.js delivers `cad` URL-encoded (":" -> "%3A"); decode once at the page +// boundary so downstream hooks/components see canonical "66:41:0204016:10" +// and re-encode exactly once when building API URLs / hrefs (prevents the +// double-encode that made backend regex reject the cad with HTTP 400). +// Regression history: PR #351 added this in Client Component; A7 split into +// Server Component (PR #356) dropped it; this restores in Server boundary. export async function generateMetadata({ params, }: PageProps): Promise { - const { cad } = await params; + const { cad: cadRaw } = await params; + const cad = decodeURIComponent(cadRaw); return { title: `Анализ ${cad} — Site Finder`, description: `Анализ инвестиционного участка ${cad}`, @@ -22,7 +29,8 @@ export async function generateMetadata({ // ── Page ────────────────────────────────────────────────────────────────────── export default async function AnalysisPage({ params }: PageProps) { - const { cad } = await params; + const { cad: cadRaw } = await params; + const cad = decodeURIComponent(cadRaw); return (