Fixed chat loading issues using pagination and resolved session disco… - #1307
Fixed chat loading issues using pagination and resolved session disco…#1307gujaratiprakash wants to merge 1 commit into
Conversation
…nnection through persistent session management.
rmyndharis
left a comment
There was a problem hiding this comment.
Thanks for putting this together — the chat-history pagination in particular addresses a real gap, and we'd like to get a version of it in. This PR mixes several independent concerns, though, and part of it no longer applies to main, so requesting changes with a concrete path forward.
Please rebase first. This branch predates #1308, which moved src/plugins/engines/* to src/engine/builtin/ and split the wwebjs adapter — the launch options and the transport-error classifier now live in wwebjs-lifecycle.ts, so the engine-side hunks won't apply. CI also hasn't run on this PR yet; please make sure the checks pass after the rebase.
Worth keeping, as separate PRs:
- Chat history pagination (dashboard) — the most valuable piece. Two implementation notes: the fetch-older offset should count DB rows already fetched rather than the merged array length (the merged list includes engine-history items, so paging by
current.lengthskips DB rows), anduseInfiniteQueryfrom React Query would fit the existing stack nicely. A spec covering the paging behavior would help. msg.downloadMedia()rejection handling and the optional-chainedmsg.id— small, correct, happy to take nearly as-is.- CDP timeout handling — the concern is real, but defaulting
protocolTimeoutto0(unlimited) removes the only bound on a hung renderer. We'd prefer a high-but-finite default plus the classifier carve-out, preserving the contract that a dead page is reported as503rather than hanging.
Please drop from this PR:
VOLUME ["/app/data"]— compose already persists data through the named volume; a bareVOLUMEcreates anonymous volumes that detach when the container is replaced.- Flipping the
AUTO_START_SESSIONSdefault in the production compose — the opt-in is deliberate (see the comment next to that line and.env.example); changing that policy is a separate discussion, and we'd rather not loosen the spec that pins it. nest-cli.json(deleteOutDir: false) — unrelated to the fixes and changes build hygiene for everyone.- The
package-lock.jsonchurn — dropping thelibcfields looks like an older-npm regeneration and can affect musl optional-dependency selection. - The Windows path in
chromium-profile-hygiene— out of scope here and untestable in the current CI.
One small note: the description mentions updates to chatMessages.test.ts and .env.example, but neither appears in the diff — worth syncing the description with the actual changes.
Happy to review the split PRs — the pagination one especially is something we want.
Fixed chat loading issues using pagination and resolved session disconnection through persistent session management.
Here is the complete Pull Request description ready to be copied into GitHub:
Fixed chat loading issues using pagination and resolved session disconnection through persistent session management.
Description
This PR addresses performance bottlenecks when loading large chat histories, prevents false transport disconnection errors during CDP command execution, catches unhandled media download rejections, and ensures full WhatsApp session persistence across Docker container rebuilds.
Summary of Major & Minor Changes:
1. Chat Pagination & Scroll UX (Dashboard Frontend & API)
getChatsandgetChatMessagesindashboard/src/services/api.tsto acceptlimitandoffsetquery parameters.useChatMessages.tswithfetchPreviousMessages(),hasMore, andisLoadingMorestates. InChatThread.tsx, scrolling near the top (scrollTop < 100px) automatically fetches older message history pages and displays a loading indicator.onOlderMessagesPrependedinuseChatScrollPosition.tsto calculate height delta (scrollTop + (newScrollHeight - oldScrollHeight)), keeping the viewport locked on the current message without jumpiness when older messages load.Chats.tsx, making tab switching (Chats / Channels / Status) instant with zero network delay.2. Session Disconnection & CDP Timeout Fixes (Backend & Engine)
PUPPETEER_PROTOCOL_TIMEOUT(defaulting to0/ unlimited) insrc/config/configuration.ts,WhatsAppWebJsAdapter,WhatsAppWebJsPlugin, andEngineFactoryto preventProtocolError: Runtime.callFunctionOn timed outduring heavyClient.getChats()operations.isPageTransportErrorinwhatsapp-web-js.adapter.tsto returnfalseontimed outerrors so protocol timeouts no longer trigger false page death reports or disconnect live sessions..catch()handling onmsg.downloadMedia()incapInboundMediaForto catch WhatsApp WebError: Getter was called with undefined dataand fall back gracefully todeclaredOnlyMedia(msg)without unhandled rejections.3. Docker Session Persistence & Auto-Reconnection
VOLUME ["/app/data"]and./data/baileysdirectory initialization toDockerfileso WhatsApp Web profiles (./data/sessions), Baileys auth state (./data/baileys), SQLite databases (main.sqlite,openwa.sqlite), API keys, and media survive container rebuilds (docker compose up --build) and recreations.docker-entrypoint.shto initialize permissions for/app/data/baileysalongsidesessionsand auto-clear stale Chromium locks (rm -f /app/data/sessions/*/Singleton*) at boot.AUTO_START_SESSIONS=${AUTO_START_SESSIONS:-true}indocker-compose.ymlso authenticated sessions automatically reconnect on container boot.Type of Change
Checklist
feature-flags.spec.ts,wwebjs-chat-transport-death.spec.ts,chatMessages.test.ts).env.example, inline JSDocs)npm run dashboard:build,tsc -b)Screenshots (if applicable)