Skip to content

fix: invalidate React Query cache on DDP reconnection - #41337

Open
prathamesh04 wants to merge 1 commit into
RocketChat:developfrom
prathamesh04:fix/reconnect-sync-thread-invalidation
Open

fix: invalidate React Query cache on DDP reconnection#41337
prathamesh04 wants to merge 1 commit into
RocketChat:developfrom
prathamesh04:fix/reconnect-sync-thread-invalidation

Conversation

@prathamesh04

@prathamesh04 prathamesh04 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes issue #41190: Open thread panels and infinite message lists do not refresh with missed messages after a DDP-only reconnection.

Root cause

On DDP reconnection, the hook correctly calls to sync new messages into the Dexie/Memory cache. However, React Query caches (used by thread panels via and infinite message lists via ) are never invalidated, so the UI does not refetch to display the newly synced messages.

Fix

After calling for each opened room on reconnect, invalidate all React Query caches under roomsQueryKeys.room(rid). This single invalidation covers thread messages, discussion messages, infinite message lists, pinned/starred messages, and all other room-scoped queries — since they are all nested children of roomsQueryKeys.room(rid).

Changes

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts: Add queryClient.invalidateQueries({ queryKey: roomsQueryKeys.room(rid) }) per opened room in the reconnect effect.

Closes #41190

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Fixed message lists and open thread panels not refreshing after reconnecting.
    • Missed messages now appear automatically when the connection is restored.

@prathamesh04
prathamesh04 requested a review from a team as a code owner July 13, 2026 12:30
@dionisio-bot

dionisio-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 27b25f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f402ac56-0955-4fa9-ae6a-3b4290e6e57c

📥 Commits

Reviewing files that changed from the base of the PR and between edbaeef and 27b25f4.

📒 Files selected for processing (2)
  • .changeset/reconnect-thread-sync-invalidation.md
  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (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/root/hooks/useLoadMissedMessages.ts
🧠 Learnings (6)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/reconnect-thread-sync-invalidation.md
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts
🔇 Additional comments (2)
.changeset/reconnect-thread-sync-invalidation.md (1)

1-5: LGTM!

apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts (1)

53-54: 🎯 Functional Correctness

No action needed. Missed messages are written to the legacy Messages store, and queryClient.invalidateQueries({ queryKey: roomsQueryKeys.room(value.rid) }) only marks room-scoped React Query entries stale; it doesn’t race with upsertMessage() or repopulate missed-message data.

			> Likely an incorrect or invalid review comment.

Walkthrough

The reconnect synchronization hook now invalidates React Query caches for opened rooms after loading missed messages, refreshing thread and message list data. A patch changeset documents the update for @rocket.chat/meteor.

Changes

Reconnect cache synchronization

Layer / File(s) Summary
Invalidate room queries after reconnect
apps/meteor/client/views/root/hooks/useLoadMissedMessages.ts, .changeset/reconnect-thread-sync-invalidation.md
useLoadMissedMessages invalidates each opened room’s React Query cache after missed messages load on reconnection, with the query client included in the effect dependencies. A patch changeset records the fix.

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

Possibly related PRs

Suggested labels: type: bug

Suggested reviewers: gabriellsh, juliaforesti, sampaiodiego

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The reconnect invalidation appears limited to room-scoped queries and does not clearly cover threads, discussions, or omnichannel history caches from #41190. Broaden the reconnect-edge invalidation to cover the thread, discussion, threads list, and omnichannel history query keys required by #41190.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: invalidating React Query cache on DDP reconnect.
Out of Scope Changes check ✅ Passed The changes stay focused on reconnect cache invalidation plus the accompanying changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@prathamesh04

Copy link
Copy Markdown
Contributor Author

This PR is ready for review — @RocketChat/backend could you take a look?

@prathamesh04

Copy link
Copy Markdown
Contributor Author

Hi @julio-rocketchat, could you please take a look when you get a chance? Thanks!

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.

Reconnect sync does not refresh open thread and infinite message lists on DDP-only reconnects

1 participant