Skip to content

refactor: simplify RoomView hooks and List - #7643

Merged
diegolmello merged 1 commit into
native-34-roomview-hooksfrom
native-34-hooks-list-simplify
Sep 3, 2026
Merged

refactor: simplify RoomView hooks and List#7643
diegolmello merged 1 commit into
native-34-roomview-hooksfrom
native-34-hooks-list-simplify

Conversation

@diegolmello

@diegolmello diegolmello commented Sep 3, 2026

Copy link
Copy Markdown
Member

Proposed changes

Cleanup pass over RoomView/hooks and RoomView/List, on top of the RoomView hooks migration.

  • useUnreadsCount hand-rolled an rxjs subscribe / setState / unsubscribe cycle. It now uses the repo's useObservable with the query in useMemo and the reduce computed during render, matching its sibling useThreadFollowing. Derived state belongs in render, not in an effect that writes state.
  • useCanPlaceLivechatOnHold (3 subscriptions) and useGoRoomActionsView (5) each subscribed per field; both are now a single useShallow selector, so an unrelated field changing no longer re-renders the consumer.
  • useRoomMessageHandlers subscribed to rid separately when it already had the room; rid is read off the room now.
  • useJumpToMessage kept an onJumpParamChangedRef live-ref layer that useChangedParam already provides for its own onChange. Both call sites pass the callback directly.
  • useRoomNavigation's cycle-breaking mirror effect had no dependency array, so it ran on every render. It now depends on [cancelJumpToMessage].
  • useHeader spread {...headerProps} into RoomHeader; all 15 props are passed explicitly.
  • The two List hook tests were the only ones outside a __tests__ directory. Moved.

Issue(s)

https://rocketchat.atlassian.net/browse/NATIVE-34

How to test or reproduce

Open a room and exercise the header, the unread badge, jump-to-message, discussion and thread navigation, and livechat on-hold. Behavior should be unchanged.

Screenshots

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

Targets native-34-roomview-hooks (#7482), not develop.

Walkthrough of every change, including the ones rejected: https://claude.ai/code/artifact/8292075a-18cc-48d5-bf3a-b5d0982603b8

One change was attempted and reverted, and is worth recording. Collapsing useScroll's onReObserve ref and its two layout effects into a single useLayoutEffect(onReObserve, [messages]) needs an exhaustive-deps suppression, and reactCompilerContract.test.ts then fails: the suppression makes React Compiler skip optimizing the entire file. That ref and ordering pattern is load-bearing for memoization on the hottest scroll hook, not lint appeasement. Note that the bail set is rule-specific, since useScroll already carries a set-state-in-effect suppression that the compiler tolerates, so the contract test is the only reliable check.

Left for follow-up:

  • useHeader depends on the whole roomUpdate object, so tunread churn rebuilds the header on every incoming message. Narrowing it requires the exact field set read by getRoomTitle / isGroupChat / isInviteSubscription, and getting that wrong silently freezes the header.
  • getRoomInfo plus goRoom is duplicated between useRoomNavigation.navToRoom and useRoomMessageHandlers.onDiscussionPress.
  • useDebounce's missing cancel-on-unmount is bolted onto two call sites here; the fix belongs in lib/methods/helpers/debounce.ts, where 21 other call sites have the same leak.
  • useCloseBanner and useReactionActions use no React API, so they are not hooks.

Local run: 38 suites, 400 tests pass; tsc clean; no new lint warnings.

Summary by CodeRabbit

  • Bug Fixes

    • Improved synchronization when cancelling message jumps during room navigation.
    • Improved unread-message count updates, including cases where no room or data is available.
    • Preserved existing room header, message handling, and live chat hold behavior.
  • Refactor

    • Streamlined room state handling to reduce redundant subscriptions and improve efficiency without changing visible behavior.
  • Tests

    • Updated test references so message and scrolling behavior continues to be validated correctly.

…rection

Collapse multi-field room store reads into single useShallow selectors, rebuild useUnreadsCount on the shared useObservable helper, remove a duplicate rid subscription and a redundant live-ref layer, give the navigation mirror effect a dependency array, pass RoomHeader props explicitly, and move the two stray List hook tests into __tests__.
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9b202ba2-f8d1-4748-a3f3-ab00a8eeb518

📥 Commits

Reviewing files that changed from the base of the PR and between ffddd22 and ed74692.

📒 Files selected for processing (9)
  • app/views/RoomView/List/hooks/__tests__/useMessages.test.tsx
  • app/views/RoomView/List/hooks/__tests__/useScroll.test.tsx
  • app/views/RoomView/hooks/useCanPlaceLivechatOnHold.ts
  • app/views/RoomView/hooks/useGoRoomActionsView.ts
  • app/views/RoomView/hooks/useHeader.tsx
  • app/views/RoomView/hooks/useJumpToMessage.ts
  • app/views/RoomView/hooks/useRoomMessageHandlers.tsx
  • app/views/RoomView/hooks/useRoomNavigation.ts
  • app/views/RoomView/hooks/useUnreadsCount.ts

Walkthrough

The changes consolidate Zustand subscriptions, replace manual unread-count subscriptions with useObservable, update callback and effect handling, make header props explicit, and correct relative paths in two hook test files.

Changes

Room hook maintenance

Layer / File(s) Summary
Room-store selector consolidation
app/views/RoomView/hooks/useCanPlaceLivechatOnHold.ts, app/views/RoomView/hooks/useGoRoomActionsView.ts, app/views/RoomView/hooks/useRoomMessageHandlers.tsx
Related room-store values now use consolidated selectors. useGoRoomActionsView applies shallow comparison.
Unread-count observable update
app/views/RoomView/hooks/useUnreadsCount.ts
The hook builds a memoized WatermelonDB observable, consumes it with useObservable, and reduces room data into the unread count.
Hook callback and render updates
app/views/RoomView/hooks/useHeader.tsx, app/views/RoomView/hooks/useJumpToMessage.ts, app/views/RoomView/hooks/useRoomNavigation.ts
The hooks pass callbacks directly, refresh cancelJumpToMessageRef when its value changes, and construct RoomHeader with explicit props.
Test import and mock path corrections
app/views/RoomView/List/hooks/__tests__/useMessages.test.tsx, app/views/RoomView/List/hooks/__tests__/useScroll.test.tsx
Test imports and Jest mock paths now match the files’ deeper directory locations. The mock behavior remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: chore


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

Comment @coderabbitai help to get the list of available commands.

@diegolmello
diegolmello merged commit d4f1b76 into native-34-roomview-hooks Sep 3, 2026
6 of 8 checks passed
@diegolmello
diegolmello deleted the native-34-hooks-list-simplify branch September 3, 2026 19:41
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