Skip to content

fix: avoid empty React Query key in RoomOpenerEmbedded#39135

Closed
sahillllllllll-bit wants to merge 1 commit into
RocketChat:developfrom
sahillllllllll-bit:fix/react-query-empty-key-room-opener
Closed

fix: avoid empty React Query key in RoomOpenerEmbedded#39135
sahillllllllll-bit wants to merge 1 commit into
RocketChat:developfrom
sahillllllllll-bit:fix/react-query-empty-key-room-opener

Conversation

@sahillllllllll-bit
Copy link
Copy Markdown
Contributor

@sahillllllllll-bit sahillllllllll-bit commented Feb 27, 2026

Proposed changes

This PR improves React Query key stability in:

apps/meteor/client/views/room/RoomOpenerEmbedded.tsx

Previously, an empty array ([]) could be passed as the queryKey when rid was falsy. Although the query was disabled, React Query would still register a query with an empty key.

The change ensures a stable and descriptive query key is always used, preventing empty key registration and improving cache correctness.

This does not alter fetching behavior or user-facing functionality.

Summary by CodeRabbit

  • Refactor
    • Simplified internal query key structure to improve application efficiency.

@sahillllllllll-bit sahillllllllll-bit requested a review from a team as a code owner February 27, 2026 11:26
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 27, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: b08f8c0

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
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2026

Walkthrough

Replaced the dynamic subscriptionsQueryKeys.subscription(rid) function call with a static array key ['subscription', rid] in a useQuery hook within RoomOpenerEmbedded.tsx, removing the corresponding import statement.

Changes

Cohort / File(s) Summary
Query Key Refactoring
apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
Converted query key from function-based subscriptionsQueryKeys.subscription(rid) to static array format ['subscription', rid], removing the subscriptionsQueryKeys import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing a dynamic query key generation approach with a static array key to avoid empty React Query keys, which is the primary fix in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/client/views/room/RoomOpenerEmbedded.tsx (1)

42-51: ⚠️ Potential issue | 🔴 Critical

Cache consistency broken: query key mismatch requires resolution.

The new inline key ['subscription', rid] does not match the format generated by subscriptionsQueryKeys.subscription(rid), which is ['subscriptions', { rid }]. Multiple parts of the codebase depend on the helper-generated key for cache operations:

  • useToggleFavoriteMutation.ts: uses setQueryData() to optimistically update the cache
  • RoomInvite.tsx, useResumeChatOnHoldMutation.ts, usePutChatOnHoldMutation.ts: use invalidateQueries() to invalidate the cache
  • useReturnChatToQueueMutation.ts: uses removeQueries() to remove cache entries

With the mismatched key, these cache operations will not affect the query in RoomOpenerEmbedded.tsx, breaking cache synchronization across the room views.

Either restore the subscriptionsQueryKeys.subscription(rid) key (re-adding the import) or update all cache operations to use the new ['subscription', rid] format.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/views/room/RoomOpenerEmbedded.tsx` around lines 42 - 51,
The useQuery in RoomOpenerEmbedded.tsx uses an inline key ['subscription', rid]
which doesn't match the project-wide helper key
subscriptionsQueryKeys.subscription(rid) (which is ['subscriptions', { rid }]);
update the queryKey to use subscriptionsQueryKeys.subscription(rid) by
re-importing subscriptionsQueryKeys and passing
subscriptionsQueryKeys.subscription(rid) to useQuery so cache ops from
useToggleFavoriteMutation, RoomInvite.tsx, useResumeChatOnHoldMutation,
usePutChatOnHoldMutation, and useReturnChatToQueueMutation target the same cache
entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/meteor/client/views/room/RoomOpenerEmbedded.tsx`:
- Around line 42-51: The useQuery in RoomOpenerEmbedded.tsx uses an inline key
['subscription', rid] which doesn't match the project-wide helper key
subscriptionsQueryKeys.subscription(rid) (which is ['subscriptions', { rid }]);
update the queryKey to use subscriptionsQueryKeys.subscription(rid) by
re-importing subscriptionsQueryKeys and passing
subscriptionsQueryKeys.subscription(rid) to useQuery so cache ops from
useToggleFavoriteMutation, RoomInvite.tsx, useResumeChatOnHoldMutation,
usePutChatOnHoldMutation, and useReturnChatToQueueMutation target the same cache
entry.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4b9303 and b08f8c0.

📒 Files selected for processing (1)
  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📜 Review details
⏰ 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: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
🧠 Learnings (7)
📓 Common learnings
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📚 Learning: 2025-12-02T22:23:49.593Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37654
File: apps/meteor/client/hooks/useAppSlashCommands.ts:32-38
Timestamp: 2025-12-02T22:23:49.593Z
Learning: In apps/meteor/client/hooks/useAppSlashCommands.ts, the `data?.forEach((command) => slashCommands.add(command))` call during render is intentional. The query is configured with `structuralSharing: false` to prevent React Query from keeping stable data references, and `slashCommands.add` is idempotent, so executing on every render is acceptable and ensures the command registry stays current.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • apps/meteor/client/views/room/RoomOpenerEmbedded.tsx

@sahillllllllll-bit sahillllllllll-bit deleted the fix/react-query-empty-key-room-opener branch February 27, 2026 11:34
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