Skip to content

[Bug] RelatedPostsFactory throws runtime error / fails when blog posts have empty or null tags #8000

Description

@suryaff733

🐛 Bug Description

When a blog post's frontmatter has an empty tags: field (or tags: null), RelatedPostsFactory fails with runtime errors and prevents the "Related Posts" section from properly calculating recommendations.

There are two failure modes:

  1. Current post has no tags: RelatedPostsFactory.getPosts() logs "RelatedPostsFactory: Tags not provided, use setTags()." and returns an empty array [], completely skipping category-based recommendations.
  2. Candidate post in the pool has no tags: addTagsPoints() in src/components/Related-Posts/relatedPostsFactory.js:69 invokes .forEach() directly on post.frontmatter.tags with no null check, throwing TypeError: Cannot read properties of null (reading 'forEach').

📍 Location of Bug

  • File: src/components/Related-Posts/relatedPostsFactory.js
  • Lines: 34–37 and 65–74
const addTagsPoints = (post, tags) => {
  const tagPoint = 1;
  const slug = getSlug(post);

  // 💥 Crashes when post.frontmatter.tags is null
  post.frontmatter.tags.forEach((tag) => {
    if (includes(tags, tag)) {
      identityMap[slug].points += tagPoint;
    }
  });
};

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions