Skip to content

A platform for community discussion. Free, open, simple.

UX: more eagerly load topic lists on scroll, avoid column shift (#44098)

Krisbab418487a46
diff --git a/app/assets/stylesheets/common/base/_topic-list.scss b/app/assets/stylesheets/common/base/_topic-list.scss
index 493836109d5..d1c08c36c61 100644
--- a/app/assets/stylesheets/common/base/_topic-list.scss
+++ b/app/assets/stylesheets/common/base/_topic-list.scss
@@ -663,6 +663,9 @@
.activity {
width: 4em;
+ // accommodates "MMM YYYY" without layout shift
+ min-width: 5.5em;
+
&:lang(zh_CN) {
width: 5.3em;
}
diff --git a/frontend/discourse/app/components/discovery/topics.gjs b/frontend/discourse/app/components/discovery/topics.gjs
index ce5c0540fac..a2a75d8d921 100644
--- a/frontend/discourse/app/components/discovery/topics.gjs
+++ b/frontend/discourse/app/components/discovery/topics.gjs
@@ -21,6 +21,8 @@ import DCountI18n from "discourse/ui-kit/d-count-i18n";
import DLoadMore from "discourse/ui-kit/d-load-more";
import dLoadingSpinner from "discourse/ui-kit/helpers/d-loading-spinner";
+export const LOAD_MORE_ROOT_MARGIN = "0px 0px 600px 0px";
+
export default class DiscoveryTopics extends Component {
@service documentTitle;
@service currentUser;
@@ -279,7 +281,12 @@ export default class DiscoveryTopics extends Component {
@topics={{@model.topics}}
/>
- <DLoadMore @action={{this.loadMore}} />
+ <DLoadMore
+ @action={{this.loadMore}}
+ @enabled={{@model.canLoadMore}}
+ @isLoading={{@model.loadingMore}}
+ @rootMargin={{LOAD_MORE_ROOT_MARGIN}}
+ />
{{/if}}
<span class="after-topic-list-plugin-outlet-wrapper">
diff --git a/frontend/discourse/tests/acceptance/topic-discovery-test.js b/frontend/discourse/tests/acceptance/topic-discovery-test.js
index 85222abf5fc..c7e14c37d87 100644
--- a/frontend/discourse/tests/acceptance/topic-discovery-test.js
+++ b/frontend/discourse/tests/acceptance/topic-discovery-test.js
@@ -1,5 +1,6 @@
import { click, currentURL, find, visit } from "@ember/test-helpers";
import { test } from "qunit";
+import { LOAD_MORE_ROOT_MARGIN } from "discourse/components/discovery/topics";
import { cloneJSON } from "discourse/lib/object";
import discoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
import topFixtures from "discourse/tests/fixtures/top-fixtures";
@@ -211,4 +212,25 @@ acceptance("Topic Discovery | Footer", function (needs) {
disableLoadMoreObserver();
}
});
+
+ test("starts loading before the reader reaches the end of the list", async function (assert) {
+ enableLoadMoreObserver();
+ const observations = stubIntersectionObserver();
+
+ try {
+ await visit("/c/dev");
+
+ const sentinel = observations.find(({ element }) =>
+ element.classList.contains("load-more-sentinel")
+ );
+
+ assert.strictEqual(
+ sentinel.options.rootMargin,
+ LOAD_MORE_ROOT_MARGIN,
+ "reaches past the bottom of the viewport, so the fetch starts before the last topic is on screen"
+ );
+ } finally {
+ disableLoadMoreObserver();
+ }
+ });
});