Skip to content

fix: Livechat-Add check for scrollPosition before restoring scroll#40123

Open
shacky wants to merge 1 commit intoRocketChat:developfrom
shacky:patch-1
Open

fix: Livechat-Add check for scrollPosition before restoring scroll#40123
shacky wants to merge 1 commit intoRocketChat:developfrom
shacky:patch-1

Conversation

@shacky
Copy link
Copy Markdown

@shacky shacky commented Apr 13, 2026

Mobile - after loading widget with delay, website scrolls to top. This is unintended behaviour caused by this line of code. We should not call it without checking if scrollPosition has been saved.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed scroll position restoration when exiting the livechat widget's mobile full-screen mode. Scroll position is now correctly restored only when a previously saved position exists, preventing unexpected scroll behavior on mobile devices.

Mobile - after loading widget with delay, website scrolls to top. This is unintended behaviour caused by this line of code. We should not call it without checking if scrollPosition has been saved.
@shacky shacky requested review from a team as code owners April 13, 2026 09:29
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Apr 13, 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

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: ef3adb63-71a0-4a70-909a-f5e1306202ba

📥 Commits

Reviewing files that changed from the base of the PR and between 9760d84 and 6026821.

📒 Files selected for processing (1)
  • packages/livechat/src/widget.ts
📜 Recent review details
⏰ 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). (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:

  • packages/livechat/src/widget.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 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:

  • packages/livechat/src/widget.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:

  • packages/livechat/src/widget.ts
🔇 Additional comments (1)
packages/livechat/src/widget.ts (1)

153-155: Good guard before restoring scroll state.

Line 153 now correctly restores document.documentElement.scrollTop only when a prior scrollPosition exists, which prevents the unintended jump-to-top path.


Walkthrough

Added a null/undefined check before restoring scroll position during mobile small-screen mode exit. The code now only sets document.documentElement.scrollTop when scrollPosition is defined, preventing assignment of uninitialized values.

Changes

Cohort / File(s) Summary
Mobile Scroll Restoration Fix
packages/livechat/src/widget.ts
Added conditional check to restore scroll position only when scrollPosition is defined, preventing uninitialized value assignment during small-screen mode exit.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a check for scrollPosition before restoring scroll in the Livechat widget, which directly addresses the bug fix described in the PR 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.

@shacky shacky changed the title fix:Livechat-Add check for scrollPosition before restoring scroll fix: Livechat-Add check for scrollPosition before restoring scroll Apr 13, 2026
Copy link
Copy Markdown
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

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.

1 participant