[Bug] RelatedPostsFactory throws runtime error / fails when blog posts have empty or null tags
Open
@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:
- Current post has no tags:
RelatedPostsFactory.getPosts()logs"RelatedPostsFactory: Tags not provided, use setTags()."and returns an empty array[], completely skipping category-based recommendations. - Candidate post in the pool has no tags:
addTagsPoints()insrc/components/Related-Posts/relatedPostsFactory.js:69invokes.forEach()directly onpost.frontmatter.tagswith no null check, throwingTypeError: 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.