mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-26 12:12:41 +02:00
Fixes a crash when a post has no tag
This commit avoids undefined.map() or null.map() is calling. When there is no tag in a post, there are two cases in frontmatter. 1) title: title categories: Technical ... 2) title: title tags: categories: Technical ... Let's look at `post.node.frontmatter.tags` in both situations. `FILE1 = /gatsby-node.js` `FILE2 = /src/components/PostTemplateDetails/index.jsx` In the first case, it is `undefined` in `FILE1`. Cheking `undefined` is already implemented at FILE1#126, so undefined.map() is not called. But it is `null` in `FILE2#22` and a crash will be occurred because it tries to run `null.map()`. In the second case, it is `null` in `FILE1` and `FILE2`. In this case, there will be two crashes in both files because both codes try to run `null.map()`. This commit avoids these crashes.
This commit is contained in:
@@ -19,7 +19,7 @@ class PostTemplateDetails extends React.Component {
|
||||
const tagsBlock = (
|
||||
<div className="post-single__tags">
|
||||
<ul className="post-single__tags-list">
|
||||
{tags.map((tag, i) =>
|
||||
{tags && tags.map((tag, i) =>
|
||||
<li className="post-single__tags-list-item" key={tag}>
|
||||
<Link to={tag} className="post-single__tags-list-item-link">
|
||||
{post.frontmatter.tags[i]}
|
||||
|
Reference in New Issue
Block a user