Skip to content

fix: use server URL instead of full server object in useSubscriptions dependency#7096

Open
deepak0x wants to merge 1 commit intoRocketChat:developfrom
deepak0x:fix/useSubscriptions-server-dependency
Open

fix: use server URL instead of full server object in useSubscriptions dependency#7096
deepak0x wants to merge 1 commit intoRocketChat:developfrom
deepak0x:fix/useSubscriptions-server-dependency

Conversation

@deepak0x
Copy link
Copy Markdown
Contributor

@deepak0x deepak0x commented Apr 3, 2026

useSubscriptions.ts was selecting the entire server Redux object and using it as a useEffect dependency. Redux reducers return a new object reference on every dispatch — even when only connecting or loading fields change — so the effect re-ran on every server connection lifecycle transition, not just when the actual server URL changed.

Each spurious fire called setLoading(true) (blanking the rooms list), unsubscribed the existing WatermelonDB observable, and created a brand new one. On a slow or unstable network, this causes the rooms list to flicker repeatedly.

The fix selects only state.server.server (a string) instead of state.server (an object). Strings are compared by value, so the effect now only fires when the server URL actually changes. This is the same pattern used throughout the rest of the codebase.

Issue(s)

Closes #7093

Screenshots

N/A — this is a behavioral fix, no UI changes.

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

Summary by CodeRabbit

  • Refactor
    • Optimized the subscription hook to more efficiently track server URL changes, reducing unnecessary re-subscriptions and improving performance when the server connection is updated.

…tate changes

Select only the server URL string instead of the entire server Redux object
in useSubscriptions hook dependency array, avoiding spurious useEffect fires
on every connection lifecycle transition (connecting/loading state changes).

Closes RocketChat#7093
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

Walkthrough

The useSubscriptions hook was updated to select only the serverUrl from Redux state instead of the entire server object, and the useEffect dependency array was adjusted to track only the serverUrl. This prevents unnecessary WatermelonDB resubscriptions during server connection state transitions.

Changes

Cohort / File(s) Summary
useSubscriptions Hook Optimization
app/views/RoomsListView/hooks/useSubscriptions.ts
Changed Redux selector from state.server to state.server.server (serverUrl extraction) and updated useEffect dependency from server to serverUrl to prevent re-subscriptions on connection state changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: using the server URL string instead of the full server object in the useSubscriptions dependency.
Linked Issues check ✅ Passed The PR directly addresses issue #7093 by changing the useEffect dependency from the entire server object to only the serverUrl string, preventing unnecessary re-subscriptions on connection state changes.
Out of Scope Changes check ✅ Passed The changes are strictly scoped to the useSubscriptions hook with only the dependency optimization in place; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

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.

bug: useSubscriptions re-queries WatermelonDB on every server connection state change, causing unnecessary rooms list flicker

1 participant