Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BA-2234 Optimistic updates #212

Merged
merged 2 commits into from
Mar 21, 2025

Conversation

tsl-ps2
Copy link
Collaborator

@tsl-ps2 tsl-ps2 commented Feb 7, 2025

Acceptance Criteria
Context
Loom: https://www.loom.com/share/9bcd130aa70f476fa3cebbb53ba338e0

Business Rules

  • Given I input text into the message box, when I send the message, then the message box should become empty immediately

  • Given I have sent a message, the message should be displayed in the chat history quickly.

  • If a message fails to be send, just remove the message from the chat history.

    • Display a toast informing this to the user.
  • Disable the send button until we know the message sending request was resolved, either successful or failed,

Approvd
https://app.approvd.io/silverlogic/BA/stories/38918

Summary by CodeRabbit

  • New Features

    • Enhanced the message subscription process by incorporating an extra identification parameter, ensuring more precise and targeted message updates.
    • Upgraded the send message functionality to include an additional detail about the message type, providing richer feedback and context during communications.
    • Updated the message list component to utilize the current profile ID for improved message handling based on user context.
    • Introduced a notification mechanism for user feedback during message sending, enhancing the overall user experience.
    • Implemented optimistic updates for message sending, allowing immediate interface feedback.
  • Version Updates

    • Updated the package version to 1.0.26, reflecting recent enhancements and modifications.

Copy link

changeset-bot bot commented Feb 7, 2025

⚠️ No Changeset found

Latest commit: a507aea

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

Copy link

coderabbitai bot commented Feb 7, 2025

Walkthrough

The changes update the GraphQL subscription and mutation definitions. The chatRoomOnMessage subscription now requires both profileId and roomId, and its corresponding hook has been modified accordingly. Additionally, the SendMessageMutation has been enhanced with the @raw_response_type directive and now returns an extra messageType field in its response. The MessagesList component and SendMessage component have also been updated to accommodate these changes.

Changes

File(s) Change Summary
packages/components/schema.graphql Updated the chatRoomOnMessage subscription to include a required profileId argument along with roomId.
packages/components/modules/messages/common/graphql/mutations/SendMessage.ts Modified SendMessageMutation by adding the @raw_response_type directive and including a new messageType field in the mutation response.
packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx Updated the useMessagesListSubscription hook to accept profileId as a required parameter.
packages/components/modules/messages/web/MessagesList/index.tsx Updated the MessagesList component to call useMessagesListSubscription with currentProfile?.id! as a second argument.
packages/components/modules/messages/web/SendMessage/index.tsx Enhanced the SendMessage component with a new notification mechanism and improved error handling, including optimistic response for immediate feedback.
packages/components/CHANGELOG.md
packages/components/package.json
Updated version number to 1.0.26 and added a changelog entry for optimistic updates in message sending.

Possibly related PRs

Suggested reviewers

  • Ronan-Fernandes
  • anicioalexandre
  • deboracosilveira

Poem

I'm a cheery rabbit, hopping through code so fine,
Adding profile IDs to subscriptions, line by line.
Messages now sparkle with a fresh field in view,
Directives and mutations, all shiny and new.
With joyful hops, I celebrate each update in this design!
🐰✨

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:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339: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:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
packages/components/modules/messages/common/graphql/mutations/SendMessage.ts

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:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339: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:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
packages/components/modules/messages/web/SendMessage/index.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:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339: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:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
  • 2 others

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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: 1

🔭 Outside diff range comments (1)
packages/components/modules/messages/graphql/subscriptions/useMessagesListSubscription.tsx (1)

20-32: Update useMemo dependency array to include profileId.

The config memo's dependency array should include profileId since it's used in the variables object.

-  }, [roomId])
+  }, [roomId, profileId])
🧹 Nitpick comments (1)
packages/components/modules/messages/SendMessage/index.tsx (1)

126-137: Consolidate error handling to avoid duplicate notifications.

Currently, similar toast messages are shown in both error branches. Consider consolidating the error handling.

 onCompleted: (response, errors) => {
-  if (errors) {
-    // TODO: handle errors
-    console.error(errors)
-    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
-  }
   const mutationErrors = response?.chatRoomSendMessage?.errors
-  if (mutationErrors) {
+  if (errors || mutationErrors) {
     console.log(mutationErrors)
+    console.error(errors)
     setFormRelayErrors(form, mutationErrors)
     sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
   }
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8de60b1 and aac16fd.

⛔ Files ignored due to path filters (1)
  • packages/components/__generated__/useMessagesListSubscription.graphql.ts is excluded by !**/__generated__/**
📒 Files selected for processing (5)
  • packages/components/modules/messages/MessagesList/index.tsx (1 hunks)
  • packages/components/modules/messages/SendMessage/index.tsx (4 hunks)
  • packages/components/modules/messages/graphql/mutations/SendMessage.ts (1 hunks)
  • packages/components/modules/messages/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
  • packages/components/schema.graphql (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/components/modules/messages/graphql/subscriptions/useMessagesListSubscription.tsx (1)

6-7: LGTM! Added profileId parameter to subscription.

The subscription now correctly includes profileId for filtering messages based on user context.

packages/components/modules/messages/graphql/mutations/SendMessage.ts (1)

8-9: LGTM! Added raw_response_type directive.

The directive ensures raw GraphQL response handling, which is beneficial for optimistic updates and error handling.

packages/components/modules/messages/SendMessage/index.tsx (2)

107-125: LGTM! Well-structured optimistic response.

The optimistic response includes all necessary fields for immediate UI feedback, improving user experience.


145-145: LGTM! Immediate form reset.

Resetting the form immediately after sending aligns with the PR objective of clearing the message box without delay.

packages/components/schema.graphql (1)

1651-1653: Updated Subscription Signatures with Profile Filtering
The subscription definitions for chat-related events have been updated to include a required profileId parameter. This change enforces that subscriptions such as chatRoomOnNewMessage, chatRoomOnRoomUpdate, and chatRoomOnMessagesCountUpdate now need both a profileId and, where applicable, a roomId. This aligns with the optimistic update requirement where the client must clearly identify the user context (via profileId) when subscribing to chat events.

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 (3)
packages/components/modules/messages/SendMessage/index.tsx (3)

128-139: Consider consolidating error handling logic.

The error handling is duplicated between the errors and mutationErrors blocks, both showing similar toast messages.

 onCompleted: (response, errors) => {
-  if (errors) {
-    // TODO: handle errors
-    console.error(errors)
-    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
-  }
   const mutationErrors = response?.chatRoomSendMessage?.errors
   if (mutationErrors) {
     console.log(mutationErrors)
     setFormRelayErrors(form, mutationErrors)
-    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
   }
+  if (errors || mutationErrors) {
+    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  }
 }

129-133: Remove TODO comment as it's already implemented.

The error handling is now implemented with toast notifications, so the TODO comment can be removed.

 if (errors) {
-  // TODO: handle errors
   console.error(errors)
   sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
 }

141-141: Remove redundant TODO comment.

The error handling is already implemented in the onError callback below.

-// TODO: handle errors
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aac16fd and bf75314.

⛔ Files ignored due to path filters (1)
  • packages/components/__generated__/SendMessageMutation.graphql.ts is excluded by !**/__generated__/**
📒 Files selected for processing (2)
  • packages/components/modules/messages/SendMessage/index.tsx (4 hunks)
  • packages/components/modules/messages/graphql/mutations/SendMessage.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Lint
  • GitHub Check: Component Test Applications and Packages
🔇 Additional comments (6)
packages/components/modules/messages/graphql/mutations/SendMessage.ts (3)

8-9: LGTM! The @raw_response_type directive addition is appropriate.

The directive ensures raw response handling, which is beneficial for optimistic updates implementation.


14-14: LGTM! The messageType field addition is well-placed.

This field helps distinguish between different types of messages in the chat interface.


38-40: LGTM! Error handling with notifications aligns with requirements.

The implementation correctly shows toast notifications for both mutation errors and network errors, satisfying the business requirement to inform users of message send failures.

Also applies to: 44-47

packages/components/modules/messages/SendMessage/index.tsx (3)

107-127: LGTM! Optimistic response implementation is thorough.

The optimistic response provides immediate feedback by showing the message in chat history before server confirmation, meeting the requirement for instant message display.


147-147: LGTM! Form reset implementation meets requirements.

The form is reset immediately after sending, satisfying the requirement to clear the message box instantly.


88-89: LGTM! Send button disable logic is correctly implemented.

The isMutationInFlight check prevents multiple submissions and disables the send button during the request, meeting the requirement.

pt-tsl
pt-tsl previously requested changes Feb 11, 2025
Copy link
Contributor

@pt-tsl pt-tsl left a comment

Choose a reason for hiding this comment

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

Check the non-null assertion for the useMessagesListSubscription hook

@tsl-ps2 tsl-ps2 force-pushed the BA-2234-optimistic-update-when-sending-message branch from bf75314 to ce4d20e Compare February 12, 2025 08:33
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce4d20e and 6365331.

📒 Files selected for processing (1)
  • packages/components/modules/messages/web/MessagesList/index.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build and Lint Packages
🔇 Additional comments (1)
packages/components/modules/messages/web/MessagesList/index.tsx (1)

1-160: Verify optimistic updates implementation in message input component.

While this component handles message display and subscription, the PR objectives require implementing optimistic updates for message sending. Please ensure that the message input component implements:

  1. Immediate message box clearing after send
  2. Instant message display in chat history
  3. Failed message removal with toast notification
  4. Send button disabling during request

Let's verify the implementation in the message input component:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for message input component and mutation handling
echo "Searching for message input component..."
fd -e tsx -e ts "MessageInput|SendMessage" packages/components/modules/messages

echo "Searching for optimistic response handling..."
rg -A 10 "optimisticResponse|onCompleted|onError" packages/components/modules/messages

Length of output: 28891


Optimistic updates are implemented in the message input component.

We verified that the SendMessage component (located at packages/components/modules/messages/web/SendMessage/index.tsx) incorporates an optimisticResponse that immediately inserts a temporary message into the chat history. Additionally, it calls form.reset() to clear the input, handles errors with toast notifications, and utilizes isMutationInFlight to disable the send button during the request.

  • The optimistic update creates a client ID using client:new_message:${Date.now()}.
  • The mutation callbacks (onCompleted and onError) manage error reporting with sendToast and reset the form.
  • The send button is disabled during the mutation via the isMutationInFlight prop passed to the UI component.

This confirms that the optimistic updates are handled in the message input component as required.

@tsl-ps2 tsl-ps2 force-pushed the BA-2234-optimistic-update-when-sending-message branch from 6365331 to da38f90 Compare February 14, 2025 15:00
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: 1

🧹 Nitpick comments (1)
packages/components/modules/messages/web/SendMessage/index.tsx (1)

127-145: Refactor error handling to reduce duplication.

The error handling code has duplicate toast messages and similar logic across different error paths.

Consider consolidating the error handling:

+const handleError = () => {
+  sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  // Remove the optimistic message from the store
+  ConnectionHandler.deleteNode(connectionID, response?.chatRoomSendMessage?.message?.node?.id)
+}

 onCompleted: (response, errors) => {
   if (errors) {
     console.error(errors)
-    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+    handleError()
   }
   const mutationErrors = response?.chatRoomSendMessage?.errors
   if (mutationErrors) {
     console.log(mutationErrors)
     setFormRelayErrors(form, mutationErrors)
-    sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+    handleError()
   }
 },
 onError: (errors) => {
   console.error(errors)
-  sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  handleError()
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6365331 and da38f90.

📒 Files selected for processing (5)
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts (1 hunks)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
  • packages/components/modules/messages/web/MessagesList/index.tsx (1 hunks)
  • packages/components/modules/messages/web/SendMessage/index.tsx (4 hunks)
  • packages/components/schema.graphql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/components/schema.graphql
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts
  • packages/components/modules/messages/web/MessagesList/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Lint Packages
🔇 Additional comments (3)
packages/components/modules/messages/web/SendMessage/index.tsx (3)

6-6: LGTM! Well-structured imports and hook setup.

The addition of useNotification and error handling utilities aligns well with the requirement to show toast notifications for failed messages.

Also applies to: 18-18, 79-79


106-126: Consider handling the pk field more robustly.

The optimistic response implementation looks good and aligns with the requirement for immediate message display. However, setting pk: 0 for all optimistic updates could potentially cause issues if multiple messages are sent in quick succession.

Consider generating a unique temporary pk value, perhaps using a negative counter to ensure no conflicts with real message IDs:

-                pk: 0, // This property is required, so we need to provide something to keep typescript happy
+                pk: -nextClientMutationId, // Use negative values to avoid conflicts with real message IDs

149-157: LGTM! Component implementation meets requirements.

The component correctly implements:

  • Disabling the send button during mutation with isLoading={isMutationInFlight}
  • Immediate message box clearing with form.reset()

@tsl-ps2 tsl-ps2 force-pushed the BA-2234-optimistic-update-when-sending-message branch from da38f90 to d643485 Compare March 3, 2025 11:30
@tsl-ps2 tsl-ps2 requested a review from pt-tsl March 3, 2025 11:30
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/CHANGELOG.md (1)

7-8: Enhance Changelog Entry Detail

The changelog entry currently reads:

- Use optimistic updates when sending messages

While this succinctly communicates the update, consider expanding this entry to capture key behaviors such as:

  • Immediately clearing the message box after sending.
  • Displaying the sent message optimistically in the chat history.
  • Disabling the send button until the message request (success or failure) resolves.
  • Removing the message and showing a toast notification on failure.

This added detail can help users understand the UX improvements without needing to refer to external documentation.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da38f90 and d643485.

📒 Files selected for processing (7)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts (1 hunks)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
  • packages/components/modules/messages/web/MessagesList/index.tsx (1 hunks)
  • packages/components/modules/messages/web/SendMessage/index.tsx (4 hunks)
  • packages/components/package.json (1 hunks)
  • packages/components/schema.graphql (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/components/package.json
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/components/modules/messages/web/MessagesList/index.tsx
  • packages/components/schema.graphql
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx
  • packages/components/modules/messages/web/SendMessage/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build and Lint Packages
  • GitHub Check: Component Test Packages
🔇 Additional comments (2)
packages/components/CHANGELOG.md (2)

3-4: Version Bump Confirmation

The new version header ## 1.0.16 is correctly added and follows semantic versioning for a patch release.


5-6: Patch Changes Section Header

The addition of the ### Patch Changes header clearly categorizes these changes and maintains the consistency of the changelog format.

@anicioalexandre anicioalexandre added the approved Review is done, and PR is approved, ready to merge. label Mar 12, 2025
@tsl-ps2 tsl-ps2 force-pushed the BA-2234-optimistic-update-when-sending-message branch from 3f1473c to ec9ca48 Compare March 14, 2025 13:58
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

♻️ Duplicate comments (1)
packages/components/modules/messages/web/SendMessage/index.tsx (1)

130-132: ⚠️ Potential issue

Add logic to remove failed messages from chat history.

The error handling implementation is missing a crucial requirement: removing the message from chat history when the send operation fails.

Consider adding cleanup logic in the error handlers:

 if (errors) {
   // TODO: handle errors
   sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  // Remove the optimistic message from the store
+  ConnectionHandler.deleteNode(connectionID, response?.chatRoomSendMessage?.message?.node?.id)
 }
 const mutationErrors = response?.chatRoomSendMessage?.errors
 if (mutationErrors) {
   setFormRelayErrors(form, mutationErrors)
   sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  // Remove the optimistic message from the store
+  ConnectionHandler.deleteNode(connectionID, response?.chatRoomSendMessage?.message?.node?.id)
 }

And in the onError handler:

onError: () => {
  sendToast('Your last message could not be sent. Please try again.', { type: 'error' })
+  // Remove the optimistic message from the store using the temporary ID
+  ConnectionHandler.deleteNode(connectionID, `client:new_message:${Date.now()}`)
},

Also applies to: 134-137, 140-142

🧹 Nitpick comments (4)
packages/components/CHANGELOG.md (1)

7-7: Grammar Correction in Optimistic Update Description

The changelog bullet
- Use optimistic update when sending message
has a grammatical inconsistency regarding number agreement. Consider revising it to:

- Use optimistic update when sending message
+ Implement optimistic updates for sending messages

This change improves clarity and ensures proper pluralization consistent with standard documentation practices.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~7-~7: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...s - Use optimistic update when sending message ## 1.0.20 ### Patch Changes - Update...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

packages/components/modules/messages/web/SendMessage/index.tsx (3)

130-130: Remove TODO comments before finalizing PR

The TODO comment should be addressed or removed, as it appears to be a remnant from development.


139-139: Remove TODO comments before finalizing PR

The TODO comment should be addressed or removed, as it appears to be a remnant from development.


110-110: Potential issue with optimistic update ID generation

Using Date.now() for generating IDs could potentially cause conflicts if multiple messages are sent in the same millisecond. Consider using a more robust ID generation method, such as UUID or incrementing a counter.

Additionally, make sure to use the same ID format in both the optimistic response and the error cleanup code to properly identify and remove failed messages.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f1473c and ec9ca48.

📒 Files selected for processing (7)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts (1 hunks)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
  • packages/components/modules/messages/web/MessagesList/index.tsx (1 hunks)
  • packages/components/modules/messages/web/SendMessage/index.tsx (4 hunks)
  • packages/components/package.json (1 hunks)
  • packages/components/schema.graphql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/components/package.json
  • packages/components/modules/messages/web/MessagesList/index.tsx
  • packages/components/schema.graphql
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts
🧰 Additional context used
🪛 LanguageTool
packages/components/CHANGELOG.md

[uncategorized] ~7-~7: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...s - Use optimistic update when sending message ## 1.0.20 ### Patch Changes - Update...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build and Lint Packages
  • GitHub Check: Component Test Packages
🔇 Additional comments (4)
packages/components/CHANGELOG.md (1)

3-5: Proper Version Header Update

The new version header "## 1.0.21" along with the "### Patch Changes" title is correctly added to indicate the start of a new release entry.

packages/components/modules/messages/web/SendMessage/index.tsx (3)

106-127: Implementation of optimistic updates looks good!

The optimistic response provides immediate UI feedback by simulating the message before server confirmation. This addresses the requirement to display messages in chat history without delay, creating a more responsive user experience.


144-144: Nice implementation of immediate form reset

Resetting the form immediately after sending satisfies the requirement to clear the message box without waiting for server response.


152-152: Verify disable send button implementation

The code passes isMutationInFlight to the SocialInput component as isLoading. This likely handles disabling the send button during message sending, which meets the requirement. Please verify that the SocialInput component properly disables the button when isLoading is true.

@tsl-ps2 tsl-ps2 force-pushed the BA-2234-optimistic-update-when-sending-message branch from ec9ca48 to a507aea Compare March 21, 2025 20:10
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/CHANGELOG.md (1)

3-8: Grammar Correction Needed.
The bullet point currently reads:
- Use optimistic update when sending message
For better clarity and consistency with the plural nature of the feature, consider updating it to:
- Use optimistic updates when sending messages

- - Use optimistic update when sending message
+ - Use optimistic updates when sending messages
🧰 Tools
🪛 LanguageTool

[uncategorized] ~7-~7: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...s - Use optimistic update when sending message ## 1.0.25 ### Patch Changes - Forwar...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ec9ca48 and a507aea.

📒 Files selected for processing (7)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts (1 hunks)
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx (2 hunks)
  • packages/components/modules/messages/web/MessagesList/index.tsx (1 hunks)
  • packages/components/modules/messages/web/SendMessage/index.tsx (4 hunks)
  • packages/components/package.json (1 hunks)
  • packages/components/schema.graphql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/components/package.json
  • packages/components/modules/messages/web/SendMessage/index.tsx
  • packages/components/schema.graphql
  • packages/components/modules/messages/common/graphql/mutations/SendMessage.ts
  • packages/components/modules/messages/web/MessagesList/index.tsx
  • packages/components/modules/messages/common/graphql/subscriptions/useMessagesListSubscription.tsx
🧰 Additional context used
🪛 LanguageTool
packages/components/CHANGELOG.md

[uncategorized] ~7-~7: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...s - Use optimistic update when sending message ## 1.0.25 ### Patch Changes - Forwar...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

@tsl-ps2 tsl-ps2 dismissed pt-tsl’s stale review March 21, 2025 20:47

Requests were addressed

@tsl-ps2 tsl-ps2 requested a review from patsluth-tsl March 21, 2025 20:58
@tsl-ps2 tsl-ps2 merged commit 21ae41b into master Mar 21, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Review is done, and PR is approved, ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants