diff --git a/CHANGELOG.md b/CHANGELOG.md index 3331e315..d735f3f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.132.0] - Not released +### Fixed +- Fixed a bug where the first partial opening of comments ("show last N") would + open one extra comment. ## [1.131.3] - 2024-05-08 ### Fixed diff --git a/src/components/post/post-comments/index.jsx b/src/components/post/post-comments/index.jsx index 34108849..58e64140 100644 --- a/src/components/post/post-comments/index.jsx +++ b/src/components/post/post-comments/index.jsx @@ -29,8 +29,6 @@ export default class PostComments extends Component { commentsAfterFold: foldConf.afterFold, minFoldedComments: foldConf.minFolded, minToCollapse: foldConf.minToCollapse, - minToSteppedFold: foldConf.minToSteppedFold, - foldStep: foldConf.foldStep, preopened: false, }; @@ -310,13 +308,25 @@ export default class PostComments extends Component { }; expandComments = (count = 0) => { + const { post, commentsAfterFold, showMoreComments, comments } = this.props; if (count > 0) { + if (post.omittedComments > 0) { + // Correction for the case when the server is configured to return less + // than 'commentsAfterFold' after a fold. We should correct the number + // of comments to be opened, otherwise more comments will be opened than + // necessary. + // + // The "comments.length - post.omittedCommentsOffset" is the server's + // number of comments after the fold. The "commentsAfterFold" is the + // client's desired number of comments after the fold. + count += comments.length - post.omittedCommentsOffset - commentsAfterFold; + } this.setState({ folded: true, addedToTail: this.state.addedToTail + count }); } else { this.setState({ folded: false, addedToTail: 0 }); } - if (this.props.post.omittedComments > 0) { - this.props.showMoreComments(this.props.post.id); + if (post.omittedComments > 0) { + showMoreComments(this.props.post.id); } };