fix: Automatically reload client if permanently stuck in reconnect lo…#41438
fix: Automatically reload client if permanently stuck in reconnect lo…#4143814-himanshu wants to merge 2 commits into
Conversation
…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.
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-03-16T21:50:37.589ZApplied to files:
🔇 Additional comments (1)
Walkthrough
ChangesServer retry recovery
Estimated code review effort: 2 (Simple) | ~5 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 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!
| useEffect(() => { | ||
| if (retryCount && retryCount >= 30 && navigator.onLine) { | ||
| window.location.reload(); | ||
| } | ||
| }, [retryCount]); |
There was a problem hiding this comment.
🩺 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 -SRepository: RocketChat/Rocket.Chat
Length of output: 9150
🏁 Script executed:
rg -n "navigator\.onLine|addEventListener\\('online'|removeEventListener\\('online'|offline|online" apps packages -SRepository: RocketChat/Rocket.Chat
Length of output: 50379
🏁 Script executed:
rg -n "retryCount" apps packages -g '!packages/i18n/**' -SRepository: 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.tsRepository: 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 detectedLatest commit: 2906622 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Proposed changes
When the client is permanently stuck in a SockJS reconnect loop despite having internet connectivity (e.g.
retryCount >= 30andnavigator.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
retryCountexceeds 30, it will automatically reload the renderer and recover the connection successfully.Further comments
N/A
Summary by CodeRabbit