layer5io / layer5io/layer5

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

Open
#8,000 1 comment 0 reactions 1 assignee View on GitHub

@NSTKrishna is already working on this.

Since Aug 26, 2026.

framework/gatsby help wanted kind/bug
Dominant language
JavaScript
Stars
1.1k
Forks
1.6k
Avg merge
2d 10h
Merged PRs (30d)
18

Description

🐛 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;
    }
  });
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.