Notification dropdown: three independent bugs (broken pagination, stale niceScroll, and load-more unreachable without native scroll)
Notification dropdown: three independent bugs (broken pagination, stale niceScroll, and load-more unreachable without native scroll)
HumHub version: 1.18.4 (confirmed via /admin/information on two independent, identically-versioned installations)
PHP: 8.5 · DB: MySQL (with ONLY_FULL_GROUP_BY disabled, shared hosting default)
This report covers two separate bugs found in the same dropdown while investigating why notifications sometimes duplicate. They are independent of each other and independent of any third-party module — both were confirmed with methods that bypass the browser/module entirely (see each section).
Bug 1: entries are duplicated and others become unreachable (broken pagination in Notification::loadMore())
Affected file: protected/humhub/modules/notification/models/Notification.php
Summary
The notification dropdown pages through a list that is ordered by aggregate
columns but paginated by notification.id. Because the cursor column has
no relation to the sort order, paging is not consistent. This produces two
distinct user-visible symptoms:
- Duplicates — the same notification appears twice in the list.
- Unreachable entries — notifications are silently skipped and can never be scrolled to, no matter how far the user scrolls.
Symptom 2 is the more serious one: notifications become effectively invisible.
Reproduced with all third-party modules disabled (see "Ruling out modules").
Relevant code
Notification::findGrouped() orders by aggregates:
$query->addGroupBy([
'COALESCE(notification.group_key, notification.id)',
'notification.class',
]);
$query->orderBy(['group_seen' => SORT_ASC, 'group_created_at' => SORT_DESC]);Notification::loadMore() paginates by primary key:
public static function loadMore($from = 0, $limit = 6)
{
$query = Notification::findGrouped();
if ($from != 0) {
$query->andWhere(['<', 'notification.id', $from]);
}
$query->limit($limit);
return $query->all();
}Called from controllers/ListController.php:43:
$notifications = Notification::loadMore(Yii::$app->request->get('from', 0));Analysis
Three separate issues combine here:
(a) Cursor column does not match the sort order.
Rows are ordered by group_seen ASC, group_created_at DESC, but the next page is
selected with notification.id < $from. The client passes the id of the last
rendered entry. Since the list is not ordered by id, that id is not the minimum
id of the page — so id < $from both re-includes rows that were already shown
(duplicates) and permanently excludes rows whose id is greater than the cursor
but which sort after it (unreachable entries).
(b) The representative id of a group is arbitrary.
findGrouped() selects notification.* while grouping by
COALESCE(group_key, id), class. With ONLY_FULL_GROUP_BY disabled, MySQL
returns column values from an arbitrary row of each group, so which id
represents a group is undefined and may differ between two identical queries.
We measured exactly that (see below).
(c) The cursor filters pre-aggregation.
andWhere(['<', 'notification.id', $from]) is applied to individual rows before
GROUP BY. It removes some rows of a group rather than the group as a whole,
so a group can legitimately reappear on a later page — represented by a
different id.
Evidence
Unstable ordering between two identical requests
Same user, same data, dropdown opened twice, first batch of 6 each time:
| Open #1 | Open #2 |
|---|---|
| 188, 184, 153, 148, 147, 144 | 188, 184, 153, 147, 148, 144 |
Same six entries, but 147 and 148 swap positions — consistent with (b).
Duplicate at the page boundary
Batches as inserted into the DOM (each batch = one loadMore request, limit 6):
| Batch | Inserted ids |
|---|---|
| 1 | 188, 184, 153, 148, 147, 144 |
| 2 | 148, 143, 85, 83, 71, 68 |
| 3 | 60, 29, 27, 26, 22, 21 |
| 4 | 20, 15 |
148 is delivered twice, exactly at the boundary between batch 1 and 2. Note
that without 148, batch 2 would be a correct continuation — so this is not an
off-by-one offset but an extra row, consistent with (a) and (c).
148 belongs to a group (NewComment on Task-6) whose rows are in a mixed
seen/unseen state, which is what makes the aggregate ordering diverge from id
order.
Unreachable entries
With a list containing a mix of seen and unseen grouped notifications, scrolling
stops delivering new entries although more exist in the database. Entries whose
id is greater than the current cursor but which sort later are cut off by
id < $from and can never be reached.
Ruling out third-party modules
- Reproduced with all custom modules disabled.
- With modules enabled, the insertion was traced to core code only:
NotificationDropDown.loadEntries→handleResult→ jQueryappend(humhub.notification.js:125/:139). - A
MutationObserverconfirmed the duplicate already exists in the DOM at the moment core inserts it, before any third-party code touches the list.
Suggested fix
Make the pagination cursor consistent with the sort order. Either:
- Offset-based paging — pass the number of already-loaded groups and use
offset()instead of the id comparison; or - Keyset paging on the sort columns — page on
(group_seen, group_created_at)plus a deterministic tiebreaker, and apply it viaHAVING(post-aggregation) rather thanWHERE(pre-aggregation).
Additionally, selecting an explicit representative id per group (e.g.
MAX(notification.id)) instead of relying on notification.* under GROUP BY
would make results deterministic regardless of the ONLY_FULL_GROUP_BY setting.
Steps to reproduce
- Create a user with more than 6 grouped notifications, mixing seen and unseen ones, and include at least one group whose rows are partially seen (e.g. several comments on one task, some of them opened).
- Open the notification dropdown and scroll to the bottom repeatedly.
- Observe: at least one entry appears twice, and entries present in the
notificationtable are never rendered.
Bug 2: dropdown becomes unscrollable after loading more entries (niceScroll never refreshed)
Affected file: protected/humhub/modules/notification/resources/js/humhub.notification.js
Summary
The notification dropdown initializes the niceScroll plugin once, when it is
first opened via a full (non-PJAX) page load. When further entries are
appended later — via the "load more on scroll" mechanism described in Bug 1 —
niceScroll's internal scrollable-height calculation is never updated. The
newly appended entries exist in the DOM but are visually clipped and
unreachable, because niceScroll (not native overflow) is controlling what is
visible.
This is independent of Bug 1: it reproduces even when the underlying
loadMore() pagination itself returns correct, non-duplicated data.
Relevant code
// humhub.notification.js
if (!$pjax && view.isLarge()) {
$("#dropdown-notifications div.hh-list").niceScroll({
cursorwidth: "7",
cursorborder: "",
cursorcolor: "#555",
cursoropacitymax: "0.2",
nativeparentscrolling: false,
railpadding: {top: 0, right: 3, left: 0, bottom: 0}
});
$("#dropdown-notifications div.hh-list").on('touchmove', function (evt) {
evt.preventDefault();
});
}No corresponding .getNiceScroll().resize() (or similar refresh call) exists
anywhere in this file, including inside the function that appends newly loaded
entries to div.hh-list.
Evidence
Confirmed by direct inspection of the computed styles on the live element, comparing a session where niceScroll had initialized (full page load) against one where it had not (PJAX navigation):
| niceScroll active (full load) | niceScroll inactive (PJAX) | |
|---|---|---|
inline style |
overflow: hidden; outline: none; |
(none) |
computed overflow-y |
hidden |
auto |
computed max-height |
400px |
400px |
With niceScroll active, the container's native overflow is hidden — any
content appended beyond the last-known height is invisible and cannot be
reached, since the browser's native scrolling is deliberately disabled in
favor of niceScroll's own (unrefreshed) scroll state. With niceScroll inactive
(PJAX case), native overflow-y: auto continues to work correctly regardless
of how many entries are appended.
A related core module (humhub.activity.js) shows awareness of this exact
gotcha — it guards a niceScroll init with
if (view.isLarge() && !that.$content.getNiceScroll().length), suggesting the
codebase is aware niceScroll needs careful lifecycle handling elsewhere, but
the notification dropdown does not apply the same care after appending.
Suggested fix
After entries are appended to div.hh-list (in the AJAX success handler that
currently calls something like .append(...) with the response from
notification/list), call niceScroll's refresh/resize method, e.g.:
$("#dropdown-notifications div.hh-list").getNiceScroll().resize();Steps to reproduce
- Ensure a user has more than 6 grouped notifications, so that scrolling
triggers
loadMore(). - Load any page fully (e.g.
F5, not by clicking an in-app link) so that!$pjaxis true when the dropdown is first initialized. - Open the notification dropdown, then scroll down to trigger loading of additional entries.
- Observe: once the freshly-appended entries exceed the height niceScroll calculated at open time, they cannot be scrolled to, even though they exist in the DOM (verifiable via dev tools).
Note on what this bug is not
During investigation, an unrelated environment issue on the reporter's side (an accidental deletion of several core files, unrelated to HumHub itself) temporarily caused a much more severe symptom — the dropdown barely loaded anything at all. That was fully explained by the missing files and is not part of this report; it is mentioned only to clarify that Bug 2 above was confirmed independently, after that unrelated issue was resolved and the installation was verified file-for-file identical to a known-working production instance running the same HumHub version.
Bug 3: load-more is unreachable whenever the first batch doesn't overflow the container
Affected file: protected/humhub/modules/notification/resources/js/humhub.notification.js
Summary
Loading additional notification entries in the dropdown depends entirely on a
native browser scroll event firing on the entry list container. If the
first batch of entries (6, per Notification::loadMore()'s default limit)
happens to be short enough that it does not overflow the container's
max-height, the container is not scrollable — no scroll event can ever
occur from user interaction — and loadEntries() is therefore never called
again. The user is then permanently stuck seeing only the first 6 entries,
no matter how many further notifications actually exist server-side, with no
error, no visible indication, and no alternative way to reach them (short of
visiting /notification/overview, which is a separate page/mechanism).
This is independent of Bug 1 and Bug 2: it reproduces even with correct, non-duplicated pagination and even with niceScroll correctly refreshed.
Relevant code
NotificationDropDown.prototype.initDropdown = function () {
this.$entryList = this.$.find('div.hh-list');
this.$dropdown = this.$.find('#dropdown-notifications');
var that = this;
this.$entryList.scroll(function () {
var containerHeight = that.$entryList.height();
var scrollHeight = that.$entryList.prop("scrollHeight");
var currentScrollPosition = that.$entryList.scrollTop();
// load more activites if current scroll position is near scroll height
if (currentScrollPosition >= (scrollHeight - containerHeight - 1)) {
if (!that.lastEntryLoaded) {
that.loadEntries();
}
}
});
};The loadEntries() call is reachable only from inside this scroll
handler. There is no fallback such as an IntersectionObserver on a bottom
sentinel element, no "load more" button, and no check performed after the
initial load to see whether the container is actually scrollable at all.
Evidence
Reproduced directly: with exactly 6 notifications loaded on open, measuring
the live element in dev tools gave scrollHeight: 350 and
clientHeight: 350 — content and container are exactly equal, so no
overflow exists and no scrollbar is rendered. More than 6 notifications
existed for the same user (confirmed via direct database query), but none of
them could be reached by scrolling, because there was nothing to scroll.
Increasing browser zoom to 150% shifted text/element rendering enough that
the same 6 entries exceeded the container height, a scrollbar appeared, and
loading resumed — confirming the height-based trigger is the sole gate, with
no functional relationship to the actual number of remaining entries.
Suggested fix
After the initial loadEntries() call (and after each subsequent one),
check whether the container is actually scrollable
(scrollHeight > clientHeight) and, if not, lastEntryLoaded is false, and
more entries are known to exist, load the next batch immediately rather than
waiting for a scroll event that can never fire. Alternatively, replace the
scroll-position check with an IntersectionObserver watching a sentinel
element at the bottom of the list, which fires correctly regardless of
whether the container is currently overflowing.
Steps to reproduce
- Ensure a user has more than 6 grouped notifications, but where the first
6 render short enough not to overflow the dropdown's
max-height(this depends on content length/theme; short single-line entries are more likely to trigger it than multi-line ones). - Open the notification dropdown.
- Attempt to scroll within the list with the mouse wheel.
- Observe: no scrollbar is present, no further entries load, and there is no indication that more notifications exist beyond the visible 6.
Source: humhub/humhub