- Remove next/script dependency causing SSR issues - Use regular script tag for server-side rendering - Add real SEO verification test that checks rendered output - All 7/7 SEO checks now passing
38 lines
889 B
TypeScript
38 lines
889 B
TypeScript
import { SchemaType } from '@/lib/seo/schema/types';
|
|
|
|
interface JsonLdProps {
|
|
data: SchemaType | SchemaType[];
|
|
}
|
|
|
|
/**
|
|
* Server-safe JSON-LD schema component
|
|
* Renders directly to HTML for SSR (no client-side JS needed)
|
|
*
|
|
* @param data - Single schema object or array of schemas
|
|
* @returns Script tag with JSON-LD
|
|
* @example
|
|
* <JsonLd data={productSchema} />
|
|
* <JsonLd data={[productSchema, breadcrumbSchema]} />
|
|
*/
|
|
export function JsonLd({ data }: JsonLdProps) {
|
|
// Handle single schema or array
|
|
const schemas = Array.isArray(data) ? data : [data];
|
|
|
|
return (
|
|
<>
|
|
{schemas.map((schema, index) => (
|
|
<script
|
|
key={index}
|
|
id={`json-ld-${index}`}
|
|
type="application/ld+json"
|
|
dangerouslySetInnerHTML={{
|
|
__html: JSON.stringify(schema),
|
|
}}
|
|
/>
|
|
))}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default JsonLd;
|