Skip to content

fix: fall back to global shareImage when page has no shareImage#201

Merged
lukasbals merged 1 commit intomainfrom
feature/pina-8536-optimize-share-image-and-metadata-for-projects-overview
Mar 31, 2026
Merged

fix: fall back to global shareImage when page has no shareImage#201
lukasbals merged 1 commit intomainfrom
feature/pina-8536-optimize-share-image-and-metadata-for-projects-overview

Conversation

@lukasbals
Copy link
Copy Markdown
Member

Problem

All four merge* utils had the same bug in their shareImage resolution logic:

// Before — broken
const metaShareImageUrl = page.attributes.metadata?.shareImage
  ? strapiMediaUrl(page.attributes.metadata.shareImage.media ?? global..., 'large')
  : DEFAULT_SHARE_IMAGE;  // ← fires even when global has a valid shareImage

When a page has no metadata (e.g. the portfolio / index page in pina-projects, where page.attributes.metadata is null), the ternary short-circuits directly to DEFAULT_SHARE_IMAGE — it never considers global.attributes.metadata.shareImage as a media source. This is why updating the shareImage in Strapi CMS had no effect.

Title and description worked fine because they use ?? chains that always reach the global fallback. Only shareImage was affected because of the early ternary exit.

Fix

Resolve the media source first (page → global → nothing), then derive the URL:

const shareImageMedia =
  page.attributes.metadata?.shareImage?.media ??
  global.attributes.metadata.shareImage?.media;

const metaShareImageUrl = shareImageMedia
  ? strapiMediaUrl(shareImageMedia, 'large')
  : DEFAULT_SHARE_IMAGE;

Applied consistently across all four merge utils:

  • mergeGlobalAndStrapiPageData
  • mergeGlobalAndStrapiBlogPostData
  • mergeGlobalAndStrapiCustomerStoryData
  • mergeGlobalAndStrapiProjectData

Tests

Added 2 new test cases to mergeGlobalAndStrapiPageData.test.ts:

  • ✅ Uses global shareImage when page has no metadata
  • ✅ Falls back to DEFAULT_SHARE_IMAGE when neither page nor global has a shareImage

All 50 tests pass.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

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

Project Deployment Actions Updated (UTC)
storybook Ready Ready Preview, Comment Mar 31, 2026 8:43am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

size-limit report 📦

Path Size
dist/index.js 603.69 KB (-0.04% 🔽)

Comment thread src/utils/mergeGlobalAndStrapiBlogPostData.ts Outdated
SchnozzleCat
SchnozzleCat previously approved these changes Mar 31, 2026
ClaraTschamon
ClaraTschamon previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Contributor

@ClaraTschamon ClaraTschamon left a comment

Choose a reason for hiding this comment

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

🚀

@lukasbals lukasbals dismissed stale reviews from ClaraTschamon and SchnozzleCat via b37d1d2 March 31, 2026 08:42
@lukasbals lukasbals force-pushed the feature/pina-8536-optimize-share-image-and-metadata-for-projects-overview branch from 441e0cd to b37d1d2 Compare March 31, 2026 08:42
@lukasbals lukasbals merged commit b37d1d2 into main Mar 31, 2026
8 checks passed
@lukasbals lukasbals deleted the feature/pina-8536-optimize-share-image-and-metadata-for-projects-overview branch March 31, 2026 08:47
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 8.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants