Follow Products.description consolidation to richText-only

Backend dropped the plain-text description field in favor of a single
richText one (see docker/payload commit 1ba8d07). Renders formatted
(bold/italic/multiple paragraphs) via the shared RichText component on
the PDP (der-eine, tasse-die-pause); everywhere else (Passend-dazu cards,
Product JSON-LD, homepage spotlight fallback) derives plain text at read
time via a new extractPlainText() helper instead of a second field.
Removes the description line from cart line items entirely — it only
bloated the cart with no real benefit there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1Hu5bZ1kZUgKhab6yNwCt
This commit is contained in:
Marco
2026-08-26 22:04:28 +00:00
parent 82696cb259
commit 7489f83564
11 changed files with 38 additions and 13 deletions
+26 -3
View File
@@ -181,7 +181,12 @@ export type Product = {
// slug-based call site.
numericId: number;
name: string;
description: string;
// Raw Lexical richText JSON — rendered formatted (bold/italic/multiple
// paragraphs) on the PDP via the shared <RichText> component. Plain-text
// consumers (Passend-dazu cards, JSON-LD) use `descriptionText` below
// instead of re-deriving text from this themselves.
description: unknown | null;
descriptionText: string;
// Not shown anywhere in the UI today — only consumed by
// buildProductSchema (JSON-LD's Product.sku), a real Schema.org property
// Google's rich-result validator looks for.
@@ -267,7 +272,7 @@ type PayloadProduct = {
id: number;
name: string;
slug: string;
description: string | null;
description: unknown | null;
sku: string | null;
price: number;
compareAtPrice: number | null;
@@ -325,16 +330,34 @@ function maxPurchasableQty(trackInventory: boolean, stock: number | null, allowB
return trackInventory && !allowBackorder ? (stock ?? 0) : null;
}
type LexicalTextNode = {
text?: string;
children?: LexicalTextNode[];
};
// Mirrors the backend's own Posts.ts extractPlainText (same shape, same
// space-joined fallback for multiple paragraphs/children) — kept as a
// separate copy rather than a shared package since it's a few lines and
// the two run in different runtimes (Payload server vs. this frontend).
function extractPlainText(node: LexicalTextNode | null | undefined): string {
if (!node) return "";
if (typeof node.text === "string") return node.text;
if (Array.isArray(node.children)) return node.children.map(extractPlainText).join(" ");
return "";
}
// Shared by getProducts() and getPostBySlug()'s relatedProduct — kept in
// one place instead of duplicating the same field mapping, which is
// exactly the kind of drift this session's Shipping Settings work was
// about eliminating elsewhere.
export function mapPayloadProduct(product: PayloadProduct): Product {
const descriptionRoot = (product.description as { root?: LexicalTextNode } | null)?.root;
return {
id: product.slug,
numericId: product.id,
name: product.name,
description: product.description ?? "",
description: product.description ?? null,
descriptionText: extractPlainText(descriptionRoot),
sku: product.sku || null,
price: product.price,
compareAtPrice: product.compareAtPrice ?? null,