fix: handle posts without tags in related posts - #8001
Conversation
Signed-off-by: NSTKrishna <krishnagehlot936@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe related posts factory now normalizes invalid tag inputs to empty arrays. Related-post scoring no longer iterates directly over missing or non-array frontmatter tags. ChangesRelated post tag handling
Estimated code review effort: 2 (Simple) | ~5 minutes Merge Risk: ⚪ Minimal · up to The PR safely handles posts with missing or null tags while preserving category-based recommendations; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Linked Issues checkExplanation The changes address issue Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Preview deployment for PR #8001 removed. This PR preview was automatically pruned because we keep only the 3 most recently updated previews on GitHub Pages to stay within deployment size limits. If needed, push a new commit to this PR to generate a fresh preview. |
|
@NSTKrishna LGTM 👍 Verified locally — fixes the null tag crash and category fallback works properly now. |
Description
This PR fixes #8000
Problem
When a blog post is authored without tags (or with
tags: null/tags: []),RelatedPostsFactoryencounters two issues:frontmatter.tagsasnullorundefined, iterating over it with.forEach()throws aTypeError: Cannot read properties of null (reading 'forEach'), causing the related posts component to crash across all blog pages.RelatedPostsFactory.getPosts()logged an error and exited early withreturn [], preventing the section from showing category-based recommendations (which carry +2 points per match).Changes Made
setTags(): UpdatedsetTags(tags)to ensurethis.tagsalways defaults to an array (Array.isArray(tags) ? tags : []), safely handlingnullandundefined.if (!tags || tags.length === 0)guard ingetPosts()so posts without tags can still recommend related posts based on matching categories.addTagsPoints(): Safely wrappedpost.frontmatter.tagsinaddTagsPoints()withArray.isArray()before calling.forEach().Notes for Reviewers
tags: [])tags: null/ omitted tagsSigned commits