Skip to content

fix: Automatically reload client if permanently stuck in reconnect lo…#41438

Open
14-himanshu wants to merge 2 commits into
RocketChat:developfrom
14-himanshu:fix/41405-reconnect-loop-reload
Open

fix: Automatically reload client if permanently stuck in reconnect lo…#41438
14-himanshu wants to merge 2 commits into
RocketChat:developfrom
14-himanshu:fix/41405-reconnect-loop-reload

Conversation

@14-himanshu

@14-himanshu 14-himanshu commented Jul 17, 2026

Copy link
Copy Markdown

Proposed changes

When the client is permanently stuck in a SockJS reconnect loop despite having internet connectivity (e.g. retryCount >= 30 and navigator.onLine === true), we now automatically trigger a reload. This robustly recreates the entire connection stream and recovers the client from the corrupted state without requiring user intervention (CTRL+R).

Issue(s)

Closes #41405

Steps to test or reproduce

  1. Start Rocket.Chat Desktop on Windows 11.
  2. Connect it normally to a Rocket.Chat workspace.
  3. Make the Rocket.Chat server temporarily unavailable (e.g. stop the stack).
  4. Wait 60-90 seconds.
  5. Start the server again.
  6. The client should automatically recover. If it gets stuck in the corrupted state where retryCount exceeds 30, it will automatically reload the renderer and recover the connection successfully.

Further comments

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Automatically reloads the page after repeated connection retries when the browser is online, helping recover from cases where the app gets stuck in a reconnect loop.
    • Improves end-user resilience by restoring the app without requiring manual refresh after prolonged reconnect attempts.

…op (RocketChat#41405)

When the client is stuck in an infinite SockJS reconnect loop despite having internet connectivity (retryCount >= 30), we now automatically force a reload to recreate the SockJS stream and recover.
@14-himanshu
14-himanshu requested a review from a team as a code owner July 17, 2026 06:42
Copilot AI review requested due to automatic review settings July 17, 2026 06:42
@dionisio-bot

dionisio-bot Bot commented Jul 17, 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

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 17, 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: 0ca1b523-9e0d-4441-83ba-0a41c2cc10fa

📥 Commits

Reviewing files that changed from the base of the PR and between a9b48a8 and 2906622.

📒 Files selected for processing (1)
  • .changeset/fix-reconnect-loop.md
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
🧠 Learnings (1)
📚 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/fix-reconnect-loop.md
🔇 Additional comments (1)
.changeset/fix-reconnect-loop.md (1)

1-6: LGTM!


Walkthrough

ServerProvider now reloads the browser after 30 or more online retries, with a patch changeset documenting the reconnect-loop fix.

Changes

Server retry recovery

Layer / File(s) Summary
Reload after prolonged retries
apps/meteor/client/providers/ServerProvider.tsx, .changeset/fix-reconnect-loop.md
Adds useEffect logic that calls window.location.reload() when retryCount >= 30 and navigator.onLine, and declares a patch release for the fix.

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

Possibly related PRs

Suggested labels: type: bug

Suggested reviewers: tassoevan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 describes the main change: automatically reloading the client when it gets stuck reconnecting.
Linked Issues check ✅ Passed The change reloads the client after repeated retries while online, which should recreate the SockJS/Meteor connection and recover without user intervention.
Out of Scope Changes check ✅ Passed The PR only adds the reconnect fix and a matching changeset entry, with no obvious unrelated code changes.
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.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/client/providers/ServerProvider.tsx`:
- Around line 182-186: Update the useEffect keyed by retryCount to also react to
connectivity changes by tracking online status with React state or subscribing
to window’s online event. When retryCount is at least 30 and the browser
transitions online, call window.location.reload(), while preserving the existing
reload behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e15c43bf-bffc-4f9b-a9e1-1dc29ec8c458

📥 Commits

Reviewing files that changed from the base of the PR and between 14d0718 and a9b48a8.

📒 Files selected for processing (1)
  • apps/meteor/client/providers/ServerProvider.tsx
📜 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/providers/ServerProvider.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/providers/ServerProvider.tsx
📚 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/providers/ServerProvider.tsx
🔇 Additional comments (1)
apps/meteor/client/providers/ServerProvider.tsx (1)

16-16: LGTM!

Comment on lines +182 to +186
useEffect(() => {
if (retryCount && retryCount >= 30 && navigator.onLine) {
window.location.reload();
}
}, [retryCount]);

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,260p' apps/meteor/client/providers/ServerProvider.tsx
printf '\n--- search ---\n'
rg -n "online|offline|retryCount|navigator\.onLine|addEventListener\\('online'|removeEventListener\\('online'" apps/meteor/client/providers/ServerProvider.tsx apps/meteor/client/providers -S

Repository: RocketChat/Rocket.Chat

Length of output: 9150


🏁 Script executed:

rg -n "navigator\.onLine|addEventListener\\('online'|removeEventListener\\('online'|offline|online" apps packages -S

Repository: RocketChat/Rocket.Chat

Length of output: 50379


🏁 Script executed:

rg -n "retryCount" apps packages -g '!packages/i18n/**' -S

Repository: RocketChat/Rocket.Chat

Length of output: 11174


🏁 Script executed:

sed -n '180,220p' packages/ddp-client/src/Connection.ts
printf '\n---\n'
sed -n '232,270p' packages/ddp-client/src/Connection.ts
printf '\n---\n'
sed -n '1,120p' apps/meteor/client/lib/sdk/meteorBackedSdk.ts

Repository: RocketChat/Rocket.Chat

Length of output: 7141


Handle the offline-to-online transition. retryCount can stay at 30 while the browser comes back online, so this effect won’t rerun unless connectivity is part of React state. Listen for window’s online event or track online status in a hook before calling window.location.reload().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/client/providers/ServerProvider.tsx` around lines 182 - 186,
Update the useEffect keyed by retryCount to also react to connectivity changes
by tracking online status with React state or subscribing to window’s online
event. When retryCount is at least 30 and the browser transitions online, call
window.location.reload(), while preserving the existing reload behavior.

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2906622

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants