fix(scroll): scroll to bottom when returning to app after backgrounding#324
Merged
chadbyte merged 1 commit intochadbyte:mainfrom Apr 20, 2026
Merged
Conversation
When switching back to Clay from another Android app (or another tab), the browser restores a stale scroll offset instead of the latest message. Add a visibilitychange listener that calls scrollToBottom() on resume, respecting the existing isUserScrolledUp guard so intentional scroll position is not clobbered. Fixes PWA scroll-position regression on Android Chrome / WebAPK.
Contributor
|
This issue has been resolved in version 2.32.0-beta.11 (main). To update, run: -- Clay Deploy Bot Build anything, with anyone, in one place. |
Contributor
|
This issue has been resolved in version 2.32.0 (stable). To update, run: -- Clay Deploy Bot Build anything, with anyone, in one place. |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Android Chrome (PWA / WebAPK), switching back to Clay from another app or tab leaves the user stranded mid-session. The browser restores a stale scroll offset instead of the latest message, so you have to manually scroll to the bottom every time you return.
Root cause
Clay has no `visibilitychange` listener. When the document becomes visible again, no scroll correction is applied, so whatever offset the browser cached (which can be well above the bottom) is what the user sees.
Fix
Add a `visibilitychange` listener that calls `scrollToBottom()` when the document becomes visible. This reuses the existing function and respects the `isUserScrolledUp` guard — if the user intentionally scrolled up to read history before backgrounding the app, their position is preserved (the "↓ Latest" button will appear as normal).
```js
document.addEventListener("visibilitychange", function () {
if (!document.hidden) {
scrollToBottom();
}
});
```
9 lines, no new state, no new dependencies.
Testing