Skip to content

fix(livechat): reset smallScreen state when leaving mobile layout#38764

Open
Shreyas2004wagh wants to merge 1 commit intoRocketChat:developfrom
Shreyas2004wagh:fix/livechat-reset-smallscreen-38763
Open

fix(livechat): reset smallScreen state when leaving mobile layout#38764
Shreyas2004wagh wants to merge 1 commit intoRocketChat:developfrom
Shreyas2004wagh:fix/livechat-reset-smallscreen-38763

Conversation

@Shreyas2004wagh
Copy link
Contributor

@Shreyas2004wagh Shreyas2004wagh commented Feb 18, 2026

Proposed changes

  • reset smallScreen to alse in the desktop branch of mediaqueryresponse
  • keep existing layout style updates unchanged

Issue(s)

Closes #38763

How to test

  1. Load the livechat widget on a page.
  2. Resize viewport to mobile so widget enters small-screen mode.
  3. Resize back to desktop.
  4. Open/close widget and verify mobile-only body scroll-lock behavior does not persist.

Notes

This is a minimal one-line fix targeting the stale internal state.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed responsive layout behavior in livechat to properly adjust when switching between small and large screen sizes.

@Shreyas2004wagh Shreyas2004wagh requested a review from a team as a code owner February 18, 2026 11:11
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 18, 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

changeset-bot bot commented Feb 18, 2026

⚠️ No Changeset found

Latest commit: c98904c

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
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

Fixes the Livechat widget's media query handler to explicitly reset the smallScreen state to false when the viewport no longer matches the small-screen condition, ensuring the widget correctly transitions from mobile to desktop layout upon resizing.

Changes

Cohort / File(s) Summary
Livechat Media Query Handler
apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js
Added explicit smallScreen = false assignment in the else branch of the media query response handler to reset the small-screen flag when viewport no longer matches the mobile breakpoint.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A widget once stuck in mobile's tight squeeze,
Now stretches and breathes with desktop's ease.
With one tiny line, the state finds its way—
From small screen to large, come resize day!

🚥 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 accurately describes the main change: resetting the smallScreen state when leaving mobile layout via a media query handler fix.
Linked Issues check ✅ Passed The pull request directly addresses issue #38763 by adding the explicit smallScreen = false assignment in the else branch, fulfilling all stated coding requirements.
Out of Scope Changes check ✅ Passed The single-line addition of smallScreen = false assignment in the media query handler's else branch is directly scoped to the stated objectives.
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
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
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 (2)
apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js (2)

724-736: ⚠️ Potential issue | 🟠 Major

Body scroll-lock left applied when widget is open during mobile→desktop resize

The one-line fix is correct for the primary described scenario (widget closed on mobile → resize → open on desktop). However, it introduces a regression for the case where the widget is already open in mobile mode when the resize occurs:

  1. openWidget is called while smallScreen === truebodyStyle is saved and overflow:hidden; position:fixed is applied to document.body.style.cssText.
  2. User resizes to desktop → mediaqueryresponse fires and sets smallScreen = false.
  3. User closes the widget → closeWidget evaluates if (smallScreen)false → skips document.body.style.cssText = bodyStylebody scroll-lock is never cleared.

Before this PR, step 3 would at least restore bodyStyle (because smallScreen was still true after resize), so the close path worked correctly even if the subsequent open was broken. The fix removes that accidental safety net without replacing it.

🐛 Proposed fix: restore body styles in `mediaqueryresponse` when transitioning while open
         } else {
+            if (smallScreen && widget.dataset.state === 'opened') {
+                document.body.style.cssText = bodyStyle;
+                document.body.scrollTop = scrollPosition;
+            }
             smallScreen = false;
             chatWidget.style.left = 'auto';
             chatWidget.style.right = '50px';
             chatWidget.style.width = widgetWidth;
         }

widget, bodyStyle, and scrollPosition are all in scope via the enclosing init closure, so no additional wiring is needed.

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

In `@apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js` around
lines 724 - 736, mediaqueryresponse currently flips smallScreen and widget
positioning but doesn't clear the mobile body scroll-lock when transitioning to
desktop while the widget is open; update mediaqueryresponse so that when
mql.matches is false and the widget is currently open (check the same
flag/condition openWidget uses), restore document.body.style.cssText from the
saved bodyStyle and restore scroll via scrollPosition before setting smallScreen
= false and applying desktop styles to chatWidget; reference mediaqueryresponse,
smallScreen, openWidget, closeWidget, bodyStyle, scrollPosition, and chatWidget
to locate and implement this restoration.

724-736: ⚠️ Potential issue | 🟠 Major

Body scroll-lock persists when the widget is open during a mobile→desktop resize

The one-line fix correctly handles the primary scenario (widget closed on mobile → resize → open on desktop). However, it introduces a regression when the widget is already open in mobile mode during the resize:

  1. openWidget runs with smallScreen === true → saves bodyStyle and applies overflow:hidden; position:fixed to document.body.
  2. User resizes to desktop → mediaqueryresponse fires → smallScreen = false (the new line).
  3. User closes the widget → closeWidget checks if (smallScreen)false → skips document.body.style.cssText = bodyStyle → the body scroll-lock is never cleared.

Before this PR, step 3 incidentally worked correctly (body was restored), because smallScreen was still true during the close. This PR removes that accidental safety net without replacing it.

🐛 Proposed fix: restore body styles on desktop transition when widget is open
         } else {
+            if (smallScreen && widget.dataset.state === 'opened') {
+                document.body.style.cssText = bodyStyle;
+                document.body.scrollTop = scrollPosition;
+            }
             smallScreen = false;
             chatWidget.style.left = 'auto';
             chatWidget.style.right = '50px';
             chatWidget.style.width = widgetWidth;
         }

widget, bodyStyle, and scrollPosition are all accessible in the mediaqueryresponse closure (declared in the enclosing init scope), so no additional wiring is needed.

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

In `@apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js` around
lines 724 - 736, mediaqueryresponse currently flips smallScreen on desktop but
doesn't undo the mobile body scroll-lock if the widget is open; update
mediaqueryresponse so that when switching from mobile to desktop (mql.matches
false) and the widget is open (check the widget's open state), restore
document.body.style.cssText = bodyStyle and restore scroll position (using
scrollPosition) before setting smallScreen = false; reference the
mediaqueryresponse closure variables widget, bodyStyle, scrollPosition,
smallScreen, and ensure this mirrors the cleanup done by closeWidget so the body
lock is not left active after a resize.
🧹 Nitpick comments (2)
apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js (2)

738-740: Pre-existing deprecated addListener API (good opportunity to modernise)

MediaQueryList.addListener() is deprecated, and you should instead use addEventListener() to watch for the change event. Since this code is already being touched, it's a low-risk opportunity to switch. Note that for Safari versions prior to 14, addEventListener on MediaQueryList throws a TypeError, so a feature-detect guard is advisable if older Safari support is required.

♻️ Proposed modernisation
-        var mql = window.matchMedia('screen and (max-device-width: 480px)');
+        var mql = window.matchMedia('screen and (max-width: 480px)');
         mediaqueryresponse(mql);
-        mql.addListener(mediaqueryresponse);
+        if (mql.addEventListener) {
+            mql.addEventListener('change', mediaqueryresponse);
+        } else {
+            mql.addListener(mediaqueryresponse);
+        }

max-device-width (physical device resolution) is also deprecated in Media Queries Level 4 — max-width (viewport width) is the modern and more semantically appropriate replacement for a responsive-layout breakpoint.

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

In `@apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js` around
lines 738 - 740, The code uses the deprecated MediaQueryList.addListener via
mql.addListener(mediaqueryresponse); replace this with a modern listener: prefer
mql.addEventListener('change', mediaqueryresponse) but guard for older Safari by
feature-detecting addEventListener and falling back to
mql.addListener(mediaqueryresponse) if absent; also consider updating the media
query string from 'screen and (max-device-width: 480px)' to 'screen and
(max-width: 480px)' to use the Level 4 semantic (adjust only if compatible with
supported browsers). Ensure you reference the mql variable and the
mediaqueryresponse callback when implementing the conditional registration and
fallback.

738-740: Modernise deprecated media query and event listener APIs

Both max-device-width (deprecated in Media Queries Level 4; viewport-based max-width is the modern replacement) and MediaQueryList.addListener() (deprecated; addEventListener('change', …) is the standard approach) are used here. Since the surrounding code is being touched, consider updating to modern equivalents.

♻️ Proposed modernisation
-        var mql = window.matchMedia('screen and (max-device-width: 480px)');
+        var mql = window.matchMedia('screen and (max-width: 480px)');
         mediaqueryresponse(mql);
-        mql.addListener(mediaqueryresponse);
+        mql.addEventListener('change', mediaqueryresponse);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js` around
lines 738 - 740, Update the media query to use viewport-based "max-width"
instead of the deprecated "max-device-width" and replace the deprecated
MediaQueryList.addListener call with the modern
MediaQueryList.addEventListener('change', ...) pattern: create the
MediaQueryList using window.matchMedia('screen and (max-width: 480px)'), call
mediaqueryresponse(mql) as before, then attach the listener via
mql.addEventListener('change', mediaqueryresponse) and include a fallback to
mql.addListener(mediaqueryresponse) for older browsers that lack
addEventListener; refer to the mql variable and the mediaqueryresponse callback
to locate where to apply these changes.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 508b4a1 and c98904c.

📒 Files selected for processing (1)
  • apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js
🧰 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/packages/rocketchat-livechat/assets/rocket-livechat.js
🧠 Learnings (1)
📚 Learning: 2025-11-19T18:20:07.720Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: packages/i18n/src/locales/en.i18n.json:918-921
Timestamp: 2025-11-19T18:20:07.720Z
Learning: Repo: RocketChat/Rocket.Chat — i18n/formatting
Learning: This repository uses a custom message formatting parser in UI blocks/messages; do not assume standard Markdown rules. For keys like Call_ended_bold, Call_not_answered_bold, Call_failed_bold, and Call_transferred_bold in packages/i18n/src/locales/en.i18n.json, retain the existing single-asterisk emphasis unless maintainers request otherwise.

Applied to files:

  • apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js
⏰ 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). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
🤖 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/packages/rocketchat-livechat/assets/rocket-livechat.js`:
- Around line 724-736: mediaqueryresponse currently flips smallScreen and widget
positioning but doesn't clear the mobile body scroll-lock when transitioning to
desktop while the widget is open; update mediaqueryresponse so that when
mql.matches is false and the widget is currently open (check the same
flag/condition openWidget uses), restore document.body.style.cssText from the
saved bodyStyle and restore scroll via scrollPosition before setting smallScreen
= false and applying desktop styles to chatWidget; reference mediaqueryresponse,
smallScreen, openWidget, closeWidget, bodyStyle, scrollPosition, and chatWidget
to locate and implement this restoration.
- Around line 724-736: mediaqueryresponse currently flips smallScreen on desktop
but doesn't undo the mobile body scroll-lock if the widget is open; update
mediaqueryresponse so that when switching from mobile to desktop (mql.matches
false) and the widget is open (check the widget's open state), restore
document.body.style.cssText = bodyStyle and restore scroll position (using
scrollPosition) before setting smallScreen = false; reference the
mediaqueryresponse closure variables widget, bodyStyle, scrollPosition,
smallScreen, and ensure this mirrors the cleanup done by closeWidget so the body
lock is not left active after a resize.

---

Nitpick comments:
In `@apps/meteor/packages/rocketchat-livechat/assets/rocket-livechat.js`:
- Around line 738-740: The code uses the deprecated MediaQueryList.addListener
via mql.addListener(mediaqueryresponse); replace this with a modern listener:
prefer mql.addEventListener('change', mediaqueryresponse) but guard for older
Safari by feature-detecting addEventListener and falling back to
mql.addListener(mediaqueryresponse) if absent; also consider updating the media
query string from 'screen and (max-device-width: 480px)' to 'screen and
(max-width: 480px)' to use the Level 4 semantic (adjust only if compatible with
supported browsers). Ensure you reference the mql variable and the
mediaqueryresponse callback when implementing the conditional registration and
fallback.
- Around line 738-740: Update the media query to use viewport-based "max-width"
instead of the deprecated "max-device-width" and replace the deprecated
MediaQueryList.addListener call with the modern
MediaQueryList.addEventListener('change', ...) pattern: create the
MediaQueryList using window.matchMedia('screen and (max-width: 480px)'), call
mediaqueryresponse(mql) as before, then attach the listener via
mql.addEventListener('change', mediaqueryresponse) and include a fallback to
mql.addListener(mediaqueryresponse) for older browsers that lack
addEventListener; refer to the mql variable and the mediaqueryresponse callback
to locate where to apply these changes.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.47%. Comparing base (508b4a1) to head (c98904c).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38764      +/-   ##
===========================================
- Coverage    70.51%   70.47%   -0.04%     
===========================================
  Files         3176     3176              
  Lines       111139   111139              
  Branches     20050    20016      -34     
===========================================
- Hits         78367    78330      -37     
- Misses       30721    30759      +38     
+ Partials      2051     2050       -1     
Flag Coverage Δ
e2e 60.45% <ø> (-0.02%) ⬇️
e2e-api 47.71% <ø> (-0.06%) ⬇️
unit 71.45% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Livechat widget does not reset smallScreen state after resizing to desktop

1 participant

Comments