From bfccd57849b676f670b8e74abfecbc8c1ce9eaab Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 24 Feb 2026 16:28:09 +0100 Subject: [PATCH] fix(products): resolve 500 mapping error by bypassing MDXRemote for complex JSX --- app/[locale]/products/[...slug]/page.tsx | 181 ++++++++++++----------- middleware.ts | 7 +- 2 files changed, 98 insertions(+), 90 deletions(-) diff --git a/app/[locale]/products/[...slug]/page.tsx b/app/[locale]/products/[...slug]/page.tsx index aa4bcf51..910ff5b8 100644 --- a/app/[locale]/products/[...slug]/page.tsx +++ b/app/[locale]/products/[...slug]/page.tsx @@ -12,7 +12,7 @@ import { mapFileSlugToTranslated, mapSlugToFileSlug } from '@/lib/slugs'; import { Metadata } from 'next'; import { getTranslations, setRequestLocale } from 'next-intl/server'; import { getProductOGImageMetadata } from '@/lib/metadata'; -import { MDXRemote } from 'next-mdx-remote/rsc'; + import Image from 'next/image'; import Link from 'next/link'; import { notFound } from 'next/navigation'; @@ -103,70 +103,70 @@ export async function generateMetadata({ params }: ProductPageProps): Promise ( -

- ), - h2: (props: any) => ( -

-

-
-
- ), - h3: (props: any) => ( -

- ), - ul: (props: any) =>
    , - section: (props: any) =>
    , - li: (props: any) => ( -
  • -
    - -
  • - ), - strong: (props: any) => , - table: (props: any) => ( -
    - - - ), - th: (props: any) => ( -
    - ), - td: (props: any) => ( - - ), - hr: () =>
    , - blockquote: (props: any) => ( -
    -
    -
    -
    - ), -}; +// const components = { +// ProductTechnicalData, +// ProductTabs, +// p: (props: any) => ( +//

    +// ), +// h2: (props: any) => ( +//

    +//

    +//
    +//
    +// ), +// h3: (props: any) => ( +//

    +// ), +// ul: (props: any) =>
      , +// section: (props: any) =>
      , +// li: (props: any) => ( +//
    • +//
      +// +//
    • +// ), +// strong: (props: any) => , +// table: (props: any) => ( +//
      +// +// +// ), +// th: (props: any) => ( +//
      +// ), +// td: (props: any) => ( +// +// ), +// hr: () =>
      , +// blockquote: (props: any) => ( +//
      +//
      +//
      +//
      +// ), +// }; export default async function ProductPage({ params }: ProductPageProps) { const { locale, slug } = await params; @@ -307,20 +307,25 @@ export default async function ProductPage({ params }: ProductPageProps) { notFound(); } - // Extract technical data for schema + // Extract technical data from MDX content (bypass MDXRemote which crashes on complex JSX-in-MDX) const technicalDataMatch = product.content.match( /technicalData=\{\}/s, ); - let technicalItems = []; + let technicalData: any = null; + let technicalItems: any[] = []; if (technicalDataMatch) { try { - const data = JSON.parse(technicalDataMatch[1]); - technicalItems = data.technicalItems || []; + technicalData = JSON.parse(technicalDataMatch[1]); + technicalItems = technicalData.technicalItems || []; } catch (e) { - console.error('Failed to parse technical data for schema', e); + console.error('Failed to parse technical data', e); } } + // Extract section HTML content + const sectionMatch = product.content.match(/
      ([\s\S]*?)<\/section>/); + const sectionHtml = sectionMatch ? sectionMatch[1] : ''; + const datasheetPath = getDatasheetPath(productSlug, locale); const isFallback = (product.frontmatter as any).isFallback; const categorySlug = slug[0]; @@ -340,22 +345,6 @@ export default async function ProductPage({ params }: ProductPageProps) { /> ); - const productComponents = { - ...components, - ProductTabs: (props: any) => , - }; - - // Pre-process content to convert raw HTML tags to Markdown so they use our custom components - const processedContent = product.content - .replace(/]*>(.*?)<\/h2>/g, '\n## $1\n') - .replace(/]*>(.*?)<\/h3>/g, '\n### $1\n') - .replace(/]*>(.*?)<\/p>/g, '\n$1\n') - .replace(/]*>(.*?)<\/ul>/gs, '\n$1\n') - .replace(/]*>(.*?)<\/li>/g, '\n- $1\n') - .replace(/]*>(.*?)<\/strong>/g, '**$1**') - .replace(/]*>/g, '') - .replace(/<\/section>/g, ''); - return (
      {/* Product Hero */} @@ -465,9 +454,25 @@ export default async function ProductPage({ params }: ProductPageProps) {
      - {/* Main Content Area */} + {/* Main Content Area - Direct rendering (bypasses MDXRemote crash) */}
      - + : null + } + sidebar={sidebar} + > + {sectionHtml && ( +
      + )} +
      {/* Datasheet Download Section - Only for Medium Voltage for now */} diff --git a/middleware.ts b/middleware.ts index e48c9afd..23164c68 100644 --- a/middleware.ts +++ b/middleware.ts @@ -45,7 +45,11 @@ export default function middleware(request: NextRequest) { const hostHeader = headers.get('x-forwarded-host') || headers.get('host') || 'testing.klz-cables.com'; + const [publicHostname] = hostHeader.split(':'); + urlObj.protocol = proto; + urlObj.hostname = publicHostname; + urlObj.port = ''; // Explicitly clear internal port (3000) effectiveRequest = new NextRequest(urlObj, { headers: request.headers, @@ -95,8 +99,7 @@ export default function middleware(request: NextRequest) { export const config = { matcher: [ - '/((?!api|_next/static|_next/image|_img|favicon.ico|manifest.webmanifest|.*\\.(?:svg|png|jpg|jpeg|gif|webp|pdf|txt|vcf|xml|webm|mp4|map)$).*)', - '/(de|en)/:path*', + '/((?!api|_next/static|_next/image|_img|favicon.ico|admin|manifest.webmanifest|.*\\.(?:svg|png|jpg|jpeg|gif|webp|pdf|txt|vcf|xml|webm|mp4|map)$).*)', '/(de|en)/:path*', ], };