Skip to content

Conversation

@vitorguima
Copy link
Contributor

@vitorguima vitorguima commented Jul 22, 2025

  • Implements a new hook: useMessagesListSubscriptionOnRn
  • Handles real-time message updates via GraphQL subscription (chatRoomOnMessage)
  • Automatically subscribes/unsubscribes on screen focus using expo useFocusEffect. Ensures clean disposal of the subscription to avoid memory leaks or duplicate events
  • Uses Relay's ConnectionHandler.getConnectionID and append new messages to the proper connection

Summary by CodeRabbit

  • New Features
    • Introduced a new hook for React Native that manages message list subscriptions, ensuring updates are received only while the relevant screen is focused.

@changeset-bot
Copy link

changeset-bot bot commented Jul 22, 2025

⚠️ No Changeset found

Latest commit: d15876c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

A new React hook, useMessagesListSubscriptionOnRn, has been added for React Native environments to manage message list subscriptions. This hook uses focus-based lifecycle management to start and stop GraphQL subscriptions. The existing web-focused useMessagesListSubscription remains unchanged.

Changes

File(s) Change Summary
packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx Added useMessagesListSubscriptionOnRn hook for React Native; no changes to existing web hook.
packages/components/CHANGELOG.md Updated changelog with new hook and version 1.2.6 release notes.
packages/components/package.json Bumped package version from 1.2.5 to 1.2.6; no other changes.

Estimated code review effort

2 (~15 minutes)

Suggested reviewers

  • pt-tsl

Poem

In the code fields where messages hop,
A new hook springs up—no need to stop!
On React Native it listens with care,
Subscribing on focus, gone when not there.
Rabbits approve, with a wiggle and cheer,
For tidy subscriptions, the message is clear! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc-with-restricted-paths.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1369:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
    at Module._load (node:internal/modules/cjs/loader:1179:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1449:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1692:14)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60048d8 and d15876c.

📒 Files selected for processing (1)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Component Test Packages
  • GitHub Check: Build and Lint Packages
  • GitHub Check: Unit Test Packages
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (1)

44-48: Improve type annotation for the environment parameter.

Consider using the proper Relay Environment type instead of any for better type safety.

+import type { Environment } from 'relay-runtime'

 export const useMessagesListSubscriptionOnRn = (
   roomId: string,
   profileId: string,
-  environment: any,
+  environment: Environment,
 ) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0952b and 28b309a.

📒 Files selected for processing (1)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (4)

1-1: LGTM! Import additions are appropriate.

The new imports are correctly used in the implementation and follow the established patterns in the codebase.

Also applies to: 3-10


49-53: LGTM! Proper disposable management and connection ID computation.

The implementation correctly uses useRef for disposable management and properly memoizes the connection ID with the right dependencies.


55-66: LGTM! Well-implemented configuration memoization.

The configuration is properly memoized with correct dependencies and maintains consistency with the existing hook pattern.


68-82: LGTM! Excellent focus-based subscription lifecycle management.

The implementation correctly uses useFocusEffect to manage subscription lifecycle, includes proper guard clauses, and ensures cleanup to prevent memory leaks. The pattern follows React Native best practices.

@vitorguima vitorguima force-pushed the feature/chat-display-sent-and-received-msg branch from fc941c8 to 60048d8 Compare July 22, 2025 17:42
@sonarqubecloud
Copy link

@vitorguima vitorguima merged commit 91101a9 into master Jul 22, 2025
8 checks passed
@vitorguima vitorguima deleted the feature/chat-display-sent-and-received-msg branch July 22, 2025 18:16
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.

3 participants