Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-reconnect-loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Automatically reload client if permanently stuck in reconnect loop (#41405)
8 changes: 7 additions & 1 deletion apps/meteor/client/providers/ServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { UploadResult, ServerContextValue } from '@rocket.chat/ui-contexts'
import { ServerContext } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import { compile } from 'path-to-regexp';
import { useMemo, useSyncExternalStore, type ReactNode } from 'react';
import { useMemo, useSyncExternalStore, useEffect, type ReactNode } from 'react';

import { sdk } from '../../app/utils/client/lib/SDKClient';
import { Info as info } from '../../app/utils/rocketchat.info';
Expand Down Expand Up @@ -179,6 +179,12 @@ export type ServerProviderProps = { children?: ReactNode };
const ServerProvider = ({ children }: ServerProviderProps) => {
const { connected, status, retryCount, retryTime } = useSyncExternalStore(subscribeStatus, getStatusSnapshot);

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

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.


const value = useMemo(
(): ServerContextValue => ({
connected,
Expand Down