Skip to content

fix(core): conditionally include optional SEO metadata#2898

Merged
jorgemoya merged 2 commits intocanaryfrom
catalyst-1798-fix-seo-when-data-is-undefined
Feb 25, 2026
Merged

fix(core): conditionally include optional SEO metadata#2898
jorgemoya merged 2 commits intocanaryfrom
catalyst-1798-fix-seo-when-data-is-undefined

Conversation

@jorgemoya
Copy link
Contributor

@jorgemoya jorgemoya commented Feb 24, 2026

What/Why?

Conditionally include optional SEO metadata fields in generateMetadata across page files. Fields description, keywords, and alternates are now only included in the returned metadata object when they have a value, using spread syntax (...(value && { key: value })). Previously, these fields were always set — potentially assigning null or an empty string — which could cause Next.js to render empty <meta> tags.

Testing

Unlighthouse report
Screenshot 2026-02-24 at 5 22 47 PM

Migration steps

Update generateMetadata in the following pages to use conditional spread syntax for optional metadata fields:

brand, category, webpages (contact + normal)

  return {
    title: pageTitle || entity.name,
-   description: metaDescription,
-   keywords: metaKeywords ? metaKeywords.split(',') : null,
+   ...(metaDescription && { description: metaDescription }),
+   ...(metaKeywords && { keywords: metaKeywords.split(',') }),
  };

For brand/[slug]/page.tsx, also guard the alternates field:

-   alternates: await getMetadataAlternates({ path: brand.path, locale }),
+   ...(brand.path && { alternates: await getMetadataAlternates({ path: brand.path, locale }) }),

blog/[blogId]/page.tsx

  return {
    title: pageTitle || blogPost.name,
-   description: metaDescription,
-   keywords: metaKeywords ? metaKeywords.split(',') : null,
+   ...(metaDescription && { description: metaDescription }),
+   ...(metaKeywords && { keywords: metaKeywords.split(',') }),
    ...(blogPost.path && {
      alternates: await getMetadataAlternates({ path: blogPost.path, locale }),
    }),
  };

blog/page.tsx

Extract the description to a variable and spread conditionally:

+ const description =
+   blog?.description && blog.description.length > 150
+     ? `${blog.description.substring(0, 150)}...`
+     : blog?.description;
+
  return {
    title: blog?.name ?? t('title'),
-   description:
-     blog?.description && blog.description.length > 150
-       ? `${blog.description.substring(0, 150)}...`
-       : blog?.description,
+   ...(description && { description }),
    ...(blog?.path && { alternates: await getMetadataAlternates({ path: blog.path, locale }) }),
  };

@vercel
Copy link

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
catalyst Ready Ready Preview, Comment Feb 24, 2026 10:45pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2026

🦋 Changeset detected

Latest commit: 990161e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jorgemoya jorgemoya marked this pull request as ready for review February 24, 2026 23:24
@jorgemoya jorgemoya requested a review from a team as a code owner February 24, 2026 23:24
Copy link
Collaborator

@migueloller migueloller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ❤️

@jorgemoya jorgemoya added this pull request to the merge queue Feb 25, 2026
Merged via the queue into canary with commit 46ee3de Feb 25, 2026
12 of 13 checks passed
@jorgemoya jorgemoya deleted the catalyst-1798-fix-seo-when-data-is-undefined branch February 25, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants