Skip to content

fix: ranks join the user card's badges instead of breaking its layout - #181

Open
ernestdefoe wants to merge 1 commit into
2.xfrom
ed/usercard-ranks-in-badges
Open

ernestdefoe wants to merge 1 commit into
2.xfrom
ed/usercard-ranks-in-badges

Conversation

@ernestdefoe

@ernestdefoe ernestdefoe commented Oct 25, 2026 •

Copy link
Copy Markdown

Fixes #170.

Problem

In Flarum 2, UserCard builds its badges in contentItems(), as UserCard-badges inside UserCard-content. The rank code still rewrote the rendered vnode the 1.x way. It searched UserCard-profile's direct children for the badges list, never found it, and spliced a second <ul class="UserCard-badges"> in at index 1, between the avatar and the content. That extra flex item pushes the rank into its own column and squeezes the user info into a narrow strip under the avatar, which is the issue's second screenshot. Users with group badges got the same column, with their group badge and rank in two separate lists.

Before, the DOM on stock 2.0.2 for a user with a rank:

UserCard-profile: [UserCard-avatar, UL.UserCard-badges [User-Rank], UserCard-content [identity, badges, info]]

Fix

The ranks are added in extend(UserCard.prototype, 'contentItems'). If the user already has a badges item, the rank <li>s join that list. They're keyed (rank-{id}) to match the keyed items from listItems. Otherwise a badges item is added at core's own priority, 90. The order (newest first) and the fof-gamification.rankAmt limit are unchanged. The vnode-walking helper the old code needed is removed. PostUser is not touched.

Tested

On stock Flarum 2.0.2 with the default theme:

  • Admin (group badge + 1 rank): UserCard-profile: [avatar, content], with badges [item-group1, User-Rank]. The rank sits next to the group badge on the name line.
  • Member with no badges and ranks, with rankAmt = 2: one badges list holding the two newest ranks, in the same order as before.
  • Redraw: repeated m.redraw.sync() doesn't duplicate ranks (2 → 2).
  • Phone (390px): the card stacks normally.

check-typings, format-check and the existing jest suite pass. js/dist is left for the build bot.

I didn't add a jest test for this. The repo's @flarum/jest-config is 2.0.0, which has no flarum/* module mapping and whose forum bootstrap assumes it runs inside core, so rendering UserCard would mean upgrading the test tooling in a layout fix. I'm happy to do that separately if you'd like.

🤖 Generated with Claude Code

In Flarum 2 the user card builds its badges in contentItems, inside
UserCard-content. Gamification looked for them among UserCard-profile's
children, never found them, and inserted a second badges list there, as
an extra column between the avatar and the content.

Fixes #170

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ernestdefoe
ernestdefoe requested a review from a team as a code owner October 25, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue where obtaining a title causes a layout shift on the user's profile page.

1 participant