framework icon indicating copy to clipboard operation
framework copied to clipboard

[2.x] PostsUserPage passes loadLimit into the page constructor argument (dead code)

Open karl-bullock opened this issue 5 months ago • 1 comments

Summary

PostsUserPage builds its PostListState with the intended per-request page size passed into the wrong constructor parameter, which makes the loadLimit field dead code. It is currently harmless, but the code is misleading and is a latent trap.

Details

framework/core/js/src/forum/components/PostsUserPage.tsx:

/** The number of activity items to load per request. */
loadLimit: number = 20;

oninit(...) {
  // ...
  this.posts = new PostListState({}, this.loadLimit);
}

PostListState's constructor signature (via PaginatedListState) is (params, page = 1, pageSize = null). So this.loadLimit (20) is passed as the page argument, not pageSize, even though the field is documented as the per-request item count.

Current behavior

It happens to be inert today, for two reasons:

  1. The constructor sets location = { page: 20 }, but show() immediately calls this.posts.refreshParams(this.params(user), 1) -> refresh(1) -> goto(1), which resets location to page 1 before any request is made. (location.page only feeds a request through getNextPageNumber() while no pages are loaded, and PostList's "load more" control is hidden until hasNext() is true, i.e. after a page has already loaded.)
  2. pageSize stays null and is then populated from the server's meta.perPage on load. Since PostResource::$defaultLimit = 20, the effective page size ends up as 20 anyway.

So loadLimit currently has no runtime effect: the profile feed paginates at the server default, not because of loadLimit.

Why it is worth noting

It is a latent trap: bumping loadLimit (e.g. to 50) to make the profile load larger pages would silently do nothing. The sibling DiscussionsUserPage has no loadLimit at all and simply relies on the server default, which is the consistent pattern.

Suggested fix

Either:

  • Remove the dead field and match DiscussionsUserPage: this.posts = new PostListState({});, or
  • Pass it in the correct position if a profile-specific size is actually wanted: new PostListState({}, 1, this.loadLimit);

Both are behavior-preserving today, since loadLimit (20) equals the server default.


Found while investigating the page[limit] handling in #4775 / #4773. Low severity, no user-visible impact. I'll look into it further before proposing a change.

karl-bullock avatar Jul 05 '26 02:07 karl-bullock

Had a look at this. The field isn't dead — fof/gamification's VotesUserPage extends this page and reads this.loadLimit straight into its own request:

page: { offset, limit: this.loadLimit },

So it's a working part of the API for subclasses, and removing it would break them. flarum/likes and flarum/mentions also subclass this page, though they don't touch the field.

The base class's own use of it is a no-op, as you say — but a harmless one. With no page[limit] sent the server applies Index::paginate($defaultLimit = 20), which is the same 20 the field asks for. Correcting the argument position would change nothing today, while making any subclass that overrides loadLimit to a different value suddenly take effect — a silent change on upgrade for no gain.

So I'd rather leave it. Closing as working as intended.

imorland avatar Aug 05 '26 19:08 imorland