Skip to content

perf: stop re-rendering the rooms list swipe layer on row content changes - #7971

Open
diegolmello wants to merge 2 commits into
developfrom
perf/room-item-rendering
Open

diegolmello wants to merge 2 commits into
developfrom
perf/room-item-rendering

Conversation

@diegolmello

@diegolmello diegolmello commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

Rows in the rooms list rebuilt their swipe layer (Touchable: the pan gesture, its worklets and shared values) whenever the row's content changed. memo(Touchable) never skipped a render, because RoomItem passed it a new children element every time. So every new message, unread count change or last-message update re-ran the whole swipe setup for that row.

The row is now split into two layers:

  • RoomItemContainer subscribes only to what the swipe layer uses (rid, type, favorite, read state) through useRoomSwipeState, and renders Touchable.
  • The new RoomItemContent subscribes to the full record and renders the presentational RoomItem, which no longer wraps Touchable.

A content-only update now re-renders the row content and leaves the swipe layer alone. Becoming read or unread, or being favorited, still re-renders the swipe layer, because its actions depend on those fields.

Two smaller cuts to per-row work:

  • Touchable and the long-press handler read the server version from the store when an action runs, instead of holding a redux subscription per row.
  • The RTL direction is read once per module instead of on every render.

Measured on an iOS simulator with a debug build, using the React DevTools profiler while 5 messages arrived in one room (two runs on each side):

develop this branch
Row Touchable renders per new message 1 0
Components rendered per new message 32–34 15–17
Render time per new message (debug build) 3.5–6.2 ms 2.3–2.5 ms

A Jest benchmark that mounts 100 real rows and updates each one's unread count shows the same direction: about 30 ms down to 7–17 ms per update of all rows. Mount time is unchanged (about 50 ms per 100 rows).

Issue(s)

How to test or reproduce

  1. Open the rooms list in expanded mode with last messages shown.
  2. From another account, send a message that mentions you in a room on the list: the row's last message, time and unread badge update live.
  3. Swipe a row right: the mark-read or mark-unread action shows, the row stays open on release, and a tap closes it without opening the room.
  4. Swipe a row left: the favorite and hide actions show; swiping another row closes the first one.
  5. Swipe an unread row right and tap mark read: the row turns read (normal weight, no badge), and swiping again shows mark unread.
  6. Tap a row: the room opens.
  7. With a screen reader or an external keyboard, long-press a row: the actions sheet offers mark read or unread, move to category (or favorite), and hide.

Screenshots

Rooms list renders (iOS simulator, debug build)

Rooms list renders

a-rooms-list-expanded.mp4

New message updates the row live

New message updates the row live

b-new-message-updates-row.mp4

Swipe right stays open, tap closes it

Swipe right stays open, tap closes it

c-swipe-right-stays-open-tap-closes.mp4

Swipe left, then another row's swipe closes it

Swipe left, closed by another row

d-swipe-left-closed-by-other-row.mp4

Tap opens the room

Tap opens the room

e-tap-row-opens-room.mp4

Mark read from the swipe action turns the row read

Mark read turns the row read

f-mark-read-flips-row-to-read.mp4

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

RoomItemContainerRenders.test.tsx fails on develop: a content-only update renders the swipe layer twice instead of once. It passes here.

I also tried dropping the useAnimatedReaction that mounts and unmounts the swipe actions, but I left it out: it showed no measurable gain, and with two fingers it could leave a row moving with no actions behind it.

Summary by CodeRabbit

  • UI Improvements
    • Room list items now display the invited indicator in both expanded and compact layouts.
    • Unread badges and update times are arranged alongside room details in standard layouts, with update times moving below the content at larger font scales to preserve readability.
  • Refactor
    • Room content and touch interactions are handled separately, while room status updates continue to be reflected in the list.

…nges

Split RoomItemContainer so the swipe layer (Touchable) subscribes only to
the fields it uses (rid, type, favorite, read state), while a new
RoomItemContent subscribes to the full record and renders the row. A new
message now re-renders the row content without rebuilding the pan gesture
and its worklets. Touchable and the long-press handler read the server
version at call time instead of holding a redux subscription per row.
@diegolmello

Copy link
Copy Markdown
Member Author

How the row render split works

Component tree. The swipe layer moved out of RoomItem and up to the container. The row content moved into a child with its own subscription:

 <RoomItemContainer>                 useRoomSnapshot(item): full record
-  <RoomItem>
-    <Touchable>                     pan gesture, worklets, shared values
-      <Wrapper> … row markup
+  <Touchable>                       swipe fields from useRoomSwipeState(item)
+    <RoomItemContent>               useRoomSnapshot(item): full record
+      <RoomItem>
+        <Wrapper> … row markup

What a new message re-renders

sequenceDiagram
    participant DB as WatermelonDB record
    participant C as RoomItemContainer
    participant T as Touchable
    participant RC as RoomItemContent
    DB->>C: change (unread, lastMessage)
    Note over C: swipe state {rid, type, favorite, isRead} is unchanged,<br/>so the cached selection is returned and nothing renders
    DB->>RC: change
    RC->>RC: new snapshot, re-render the row content
    Note over T: not rendered
Loading

When the swipe layer does re-render. useRoomSwipeState returns the same object while its four fields are equal, so Touchable re-renders only when its actions would change:

getSnapshot()
  next = { rid, type, favorite: !!f, isRead: getIsRead(record) }
  if cached is for this item and its fields equal next
    return cached          # no render
  cache next and return it # render: read/unread flip, (un)favorite, new item

Per-row work removed outside renders

 Touchable
-  useAppSelector(server.version)    # one redux subscription per row
+  store.getState().server.version   # read when mark read/unread runs
-  direction = isRTL ? -1 : 1        # every render
+  direction                         # once per module

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Room item state, content rendering, and touch interactions now use separate hooks and components. The container composes these parts, and the tests cover room updates, swipe state, and long-press handling.

Changes

Room item rendering and interaction

Layer / File(s) Summary
Room state contracts and snapshots
app/containers/RoomItem/interfaces.ts, app/containers/RoomItem/hooks/*
The room item interfaces now separate content props from swipe state. Snapshot helpers are exported, and useRoomSwipeState provides cached room identifiers, subscription type, favorite status, and read status.
Room content and touch components
app/containers/RoomItem/RoomItem.tsx, app/containers/RoomItem/RoomItemContent.tsx, app/containers/RoomItem/Touchable.tsx, app/containers/RoomItem/RoomItem.stories.tsx
RoomItemContent derives display data from the room item. RoomItem renders content without wrapping it in Touchable. The Storybook wrapper composes the components, and Touchable reads the server version from the Redux store when toggling read status.
Container composition and validation
app/containers/RoomItem/index.tsx, app/containers/RoomItem/__tests__/*
The container passes swipe state and display inputs to Touchable and RoomItemContent. Tests cover room updates, read and favorite state, long-press handling, and whether room content updates cause another swipe-layer render.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant RoomItemContainer
  participant useRoomSwipeState
  participant Touchable
  participant RoomItemContent
  participant RoomItem
  RoomItemContainer->>useRoomSwipeState: Read room swipe state
  RoomItemContainer->>Touchable: Pass swipe state and touch handlers
  RoomItemContainer->>RoomItemContent: Pass item and display properties
  RoomItemContent->>RoomItem: Pass derived room display data
Loading

Suggested labels: type: chore

Suggested reviewers: otaviostasiak, reinaldonetof, aleksandernsilva

Merge Risk: Minimal · up to d448d

This change separates the swipe layer from row content so message updates re-render less. It also adds tests for the swipe layer's render count and its read and favorite updates. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title says the change stops re-rendering the rooms list swipe layer when row content changes. The raw summary shows this is the main change: RoomItemContainer now subscribes only to swipe-relevant…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title says the change stops re-rendering the rooms list swipe layer when row content changes. The raw summary shows this is the main change: RoomItemContainer now subscribes only to swipe-relevant fields (rid, type, favorite, read state), while RoomItemContent handles full-record content and renders the presentational RoomItem. The objectives state that content-only updates no longer re-render Touchable, and read or favorite changes still re-render the swipe layer. The title matches this, and it also names the perf goal. The title is concise and specific.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Errors were encountered while retrieving linked issues.

Errors: 1

  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4dfe165b-9e17-42a5-a2e5-0a0ce9e0cbc7
Commits

Reviewing files that changed from the base of the PR and between 0573d1a and d448d53.

Files selected for processing: 11

  • app/containers/RoomItem/RoomItem.stories.tsx
  • app/containers/RoomItem/RoomItem.tsx
  • app/containers/RoomItem/RoomItemContent.tsx
  • app/containers/RoomItem/Touchable.tsx
  • app/containers/RoomItem/__tests__/RoomItemContainer.test.tsx
  • app/containers/RoomItem/__tests__/RoomItemContainerLongPress.test.tsx
  • app/containers/RoomItem/__tests__/RoomItemContainerRenders.test.tsx
  • app/containers/RoomItem/hooks/useRoomSnapshot.ts
  • app/containers/RoomItem/hooks/useRoomSwipeState.ts
  • app/containers/RoomItem/index.tsx
  • app/containers/RoomItem/interfaces.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: CodeRabbit
  • GitHub Check: ESLint and Test / run-eslint-and-test
  • GitHub Check: E2E Shard Preflight
Additional context used

Learnings: 6

Learning: 2026-09-24T15:31:10.526Z

Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7719
File: app/containers/RoomItem/Touchable.tsx:0-0
Timestamp: 2026-09-24T15:31:10.526Z
Learning: In RocketChat/Rocket.Chat.ReactNative, `app/containers/RoomItem/Touchable.tsx` intentionally closes an open swipe row when a touch begins on another swipe-enabled row, even if that touch starts a vertical scroll. A touch that starts on the open row itself must not close it.

Applied to files:

  • app/containers/RoomItem/RoomItem.stories.tsx
Learning: 2026-09-24T15:22:59.759Z

Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7719
File: app/containers/RoomItem/Touchable.tsx:161-162
Timestamp: 2026-09-24T15:22:59.759Z
Learning: In `app/containers/RoomItem/Touchable.tsx`, the pan gesture is disabled when `swipeEnabled` is false. `closeOpenSwipeItem(rid)` runs only in that gesture's `onBegin` callback, so a press on a swipe-disabled row does not close another row through this callback.

Applied to files:

  • app/containers/RoomItem/RoomItem.stories.tsx
Learning: 2026-10-31T15:38:38.488Z

Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2026-10-31T15:38:38.488Z
Learning: Applicability reference:
AGENTS.md: # CLAUDE.md
## Workflow
- **Reviewing**: apply `CODING_STANDARDS.md`.

Source excerpt:
# Coding Standards

## JSX props

Pass every prop explicitly: `<Avatar text={text} size={size} />`. Spread props (`{...props}`) in JSX are a violation, even when forwarding.

Applied to files:

  • app/containers/RoomItem/RoomItem.stories.tsx
  • app/containers/RoomItem/RoomItem.tsx
  • app/containers/RoomItem/__tests__/RoomItemContainerRenders.test.tsx
Learning: 2026-10-31T15:39:24.255Z

Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CONTEXT.md:0-0
Timestamp: 2026-10-31T15:39:24.255Z
Learning: Applicability reference:
AGENTS.md: # CLAUDE.md
## Project Overview
Read CONTEXT.md.

Source excerpt:
# Ubiquitous Language

## Rooms & Conversations

- **Room Membership**: exactly one of:
  - **Subscribed Room**: Subscription exists, status not `invited`. _Avoid:_ Joined room
  - **Invited**: Subscription exists, status `invited`, not yet accepted
  - **Preview Mode**: no Subscription; Room data comes from navigation params or a REST lookup; lasts until the user joins
  - _Avoid:_ Joined flag, membership

Applied to files:

  • app/containers/RoomItem/RoomItemContent.tsx
Learning: 2026-10-31T15:39:24.255Z

Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CONTEXT.md:0-0
Timestamp: 2026-10-31T15:39:24.255Z
Learning: Applicability reference:
AGENTS.md: # CLAUDE.md
## Project Overview
Read CONTEXT.md.

Source excerpt:
# Ubiquitous Language

## Rooms & Conversations

- **Room**: server-side conversation container with shared state (name, type, settings). _Avoid:_ Chat, conversation

Applied to files:

  • app/containers/RoomItem/RoomItemContent.tsx
Learning: 2026-08-21T17:03:38.505Z

Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7592
File: app/sagas/__tests__/init.test.ts:0-0
Timestamp: 2026-08-21T17:03:38.505Z
Learning: In TypeScript test files in the Rocket.Chat.ReactNative repository, do not require explicit return-type annotations on `it()` callbacks when surrounding test suites omit them. Do not require an explicit parameter type when TypeScript correctly infers it from a typed mocked function signature, such as `UserPreferences.getString`.

Applied to files:

  • app/containers/RoomItem/__tests__/RoomItemContainer.test.tsx

This branch is waiting to be deployed

3 waiting deployments
android_build — d448d536 Waiting Dec 1, 2026 by diegolmello via Build Android / Hold #8154
ios_build — d448d536 Waiting Dec 1, 2026 by diegolmello via Build iOS / Hold #8154
approve_e2e_testing — d448d536 Waiting Dec 1, 2026 by diegolmello via E2E Hold #8154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant