Skip to content

fix(scroll): scroll to bottom when returning to app after backgrounding#324

Merged
chadbyte merged 1 commit intochadbyte:mainfrom
akuehner:fix/pwa-scroll-on-resume
Apr 20, 2026
Merged

fix(scroll): scroll to bottom when returning to app after backgrounding#324
chadbyte merged 1 commit intochadbyte:mainfrom
akuehner:fix/pwa-scroll-on-resume

Conversation

@akuehner
Copy link
Copy Markdown
Contributor

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

  • Open Clay in Android Chrome PWA, send/receive messages so the session has content
  • Switch to another app, then switch back — should land at the latest message
  • Scroll up intentionally, switch away and back — should stay scrolled up (button appears)

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.
@chadbyte chadbyte merged commit 70a6751 into chadbyte:main Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This issue has been resolved in version 2.32.0-beta.11 (main).

To update, run:

npx clay-server@2.32.0-beta.11

-- Clay Deploy Bot

Build anything, with anyone, in one place.

@github-actions
Copy link
Copy Markdown
Contributor

This issue has been resolved in version 2.32.0 (stable).

To update, run:

npx clay-server@2.32.0

-- Clay Deploy Bot

Build anything, with anyone, in one place.

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.

2 participants