davila7/claude-code-templates · info
No message element to scroll to
Error message
No message element to scroll to
What it means
scrollToMessage() guards against being called with a null/undefined messageElement and returns early with this warning. It means the caller tried to scroll to a message that was never located in the DOM (typically after the 'Could not find message with ID' retry loop gave up).
Source
Thrown at cli-tool/src/analytics-web/chats_mobile.html:4126
// Try to load more messages
if (this.messagesPagination.hasMore && !this.messagesPagination.isLoading) {
console.log(`🔄 Loading more messages to find message ${messageId}...`);
await this.loadMoreMessages(this.selectedConversationId, false);
attempts++;
// Wait a bit for messages to render
await new Promise(resolve => setTimeout(resolve, 500));
} else {
// No more messages to load or already loading
console.warn('Could not find message with ID', messageId, 'after', attempts, 'attempts');
break;
}
}
}
scrollToMessage(messageElement) {
if (!messageElement) {
console.warn('No message element to scroll to');
return;
}
const messagesContainer = document.getElementById('chatMessages');
if (!messagesContainer) return;
// Get the absolute position of the message within the scrollable container
const containerTop = messagesContainer.getBoundingClientRect().top;
const messageTop = messageElement.getBoundingClientRect().top;
const containerHeight = messagesContainer.clientHeight;
const messageHeight = messageElement.offsetHeight;
// Calculate the current scroll position
const currentScroll = messagesContainer.scrollTop;
// Calculate the offset from the top of the container
const messageOffsetFromTop = messageTop - containerTop;
View on GitHub (pinned to a0851ed10c)
Solutions
- Fix the upstream lookup so a valid element is found before calling scrollToMessage (see the message-ID retry warning)
- Null-check the element at the call site and show user feedback instead of calling scrollToMessage(null)
- Re-query the element right before scrolling if the DOM may have re-rendered
- Ensure the selector/id used for lookup matches the rendered element's attributes
Example fix
// before
scrollToMessage(document.getElementById(messageId)); // may pass null
// after
const el = document.getElementById(messageId);
if (el) {
scrollToMessage(el);
} else {
console.info('Message unavailable; skipping scroll');
} Defensive patterns
Strategy: type-guard
Validate before calling
const el = document.querySelector(`[data-message-id="${CSS.escape(messageId)}"]`);
if (!el) { console.info('no element; skipping scroll'); return; } Type guard
const isScrollTarget = (el) => el instanceof HTMLElement && el.isConnected;
Prevention
- Null-check lookups before calling DOM-scroll helpers
- Use optional chaining at call sites: found?.scrollIntoView()
- Re-query elements after async renders instead of reusing stale references
When it happens
Trigger: Passing the result of querySelector/lookup that returned null into scrollToMessage; calling it after the retry loop in scrollToMessageById broke out without finding the element; race where the element was removed from the DOM between lookup and scroll.
Common situations: Deep links to nonexistent or deleted messages; messages filtered/hidden by UI state; element lookup by the wrong selector or id format; re-render wiping the DOM between finding and scrolling.
Related errors
AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28).
Data as JSON: /api/errors/cb8b2254528338ea.
Report an issue: GitHub.