diff --git a/app/assets/javascripts/discourse/app/components/post-list/index.gjs b/app/assets/javascripts/discourse/app/components/post-list/index.gjs index 63b7f6803ff..45a25a0bd7b 100644 --- a/app/assets/javascripts/discourse/app/components/post-list/index.gjs +++ b/app/assets/javascripts/discourse/app/components/post-list/index.gjs @@ -52,20 +52,17 @@ export default class PostList extends Component { } this.loading = true; - const posts = this.args.posts; - if (posts && posts.length) { - try { - const newPosts = await this.args.fetchMorePosts(); - this.args.posts.addObjects(newPosts); + try { + const newPosts = await this.args.fetchMorePosts(); + this.args.posts?.addObjects(newPosts); - if (newPosts.length === 0) { - this.canLoadMore = false; - } - } catch (error) { - popupAjaxError(error); - } finally { - this.loading = false; + if (newPosts.length === 0) { + this.canLoadMore = false; } + } catch (error) { + popupAjaxError(error); + } finally { + this.loading = false; } } diff --git a/app/assets/javascripts/discourse/app/controllers/group-activity-posts.js b/app/assets/javascripts/discourse/app/controllers/group-activity-posts.js index bc18a72001c..522a83d4eb8 100644 --- a/app/assets/javascripts/discourse/app/controllers/group-activity-posts.js +++ b/app/assets/javascripts/discourse/app/controllers/group-activity-posts.js @@ -9,7 +9,8 @@ export default class GroupActivityPostsController extends Controller { @action async fetchMorePosts() { const posts = this.model; - const before = posts[posts.length - 1].created_at; + const before = + posts.length > 0 ? posts[posts.length - 1]?.created_at : undefined; const group = this.group.model; const categoryId = this.groupActivity.category_id; const opts = { before, type: this.type, categoryId };