From 49802d667f1c5bb1dcb0f349b1581237c083c949 Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 8 May 2025 13:34:39 -0400 Subject: [PATCH] DEV: Remove post length check to allow loading to end (#32648) As reported: https://meta.discourse.org/t/endless-spinning-on-user-activity-of-user-without-activity/365313 If a user has no posts, their post list will show a loading spinner indefinitely ![image](https://github.com/user-attachments/assets/23af7c84-444e-4f6b-bfbb-dcc84162b1f6) This is because if there are no posts we never set `canLoadMore` or `loading` to `false` If we always check for new posts we avoid the issue. ![image](https://github.com/user-attachments/assets/8bfb0267-7b3c-44cc-8f77-8d442598c50d) --- .../app/components/post-list/index.gjs | 21 ++++++++----------- .../app/controllers/group-activity-posts.js | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) 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 };