{"record":{"id":"3121a8b4047800fa","repo":"davila7/claude-code-templates","slug":"could-not-find-message-with-id","errorCode":null,"errorMessage":"Could not find message with ID","messagePattern":"Could not find message with ID","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-tool/src/analytics-web/chats_mobile.html","lineNumber":4118,"sourceCode":"\n                    if (messageElement) {\n                        // Found the message!\n                        this.scrollToMessage(messageElement);\n                        this.highlightCurrentMatchById(messageId);\n                        return;\n                    }\n\n                    // Try to load more messages\n                    if (this.messagesPagination.hasMore && !this.messagesPagination.isLoading) {\n                        console.log(`🔄 Loading more messages to find message ${messageId}...`);\n                        await this.loadMoreMessages(this.selectedConversationId, false);\n                        attempts++;\n\n                        // Wait a bit for messages to render\n                        await new Promise(resolve => setTimeout(resolve, 500));\n                    } else {\n                        // No more messages to load or already loading\n                        console.warn('Could not find message with ID', messageId, 'after', attempts, 'attempts');\n                        break;\n                    }\n                }\n            }\n\n            scrollToMessage(messageElement) {\n                if (!messageElement) {\n                    console.warn('No message element to scroll to');\n                    return;\n                }\n\n                const messagesContainer = document.getElementById('chatMessages');\n                if (!messagesContainer) return;\n\n                // Get the absolute position of the message within the scrollable container\n                const containerTop = messagesContainer.getBoundingClientRect().top;\n                const messageTop = messageElement.getBoundingClientRect().top;\n                const containerHeight = messagesContainer.clientHeight;","sourceCodeStart":4100,"sourceCodeEnd":4136,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics-web/chats_mobile.html#L4100-L4136","documentation":"scrollToMessageById retries finding a DOM element with the given message ID, waiting 500ms per attempt (e.g. for lazy-loaded messages to render). After exhausting attempts with no matching element and nothing left to load, it warns and breaks out of the loop — the scroll simply never happens.","triggerScenarios":"Calling scrollToMessageById with a message ID that doesn't exist in the loaded conversation (stale deep-link, deleted message), or when lazy loading finished but the target message was never rendered (filtered out, pagination limit, or DOM id mismatch between the API's message ID and the rendered element's id attribute).","commonSituations":"Deep links/URLs to old messages that were deleted; message IDs from an export that differ from runtime DOM ids; very long conversations where the target is beyond the lazy-load window; UI filters hiding the target message.","solutions":["Verify the message ID actually exists in the conversation data returned by the API","Check how message elements get their DOM id and confirm it matches the ID you pass (no prefix/suffix mismatch)","Increase the attempts/timeout or trigger loading older messages before scrolling","Handle the failure gracefully — show a 'message not found' notice instead of silently not scrolling"],"exampleFix":"// before\nscrollToMessageById('msg_123'); // warns if never rendered\n\n// after\nconst el = document.querySelector('[data-message-id=\"msg_123\"]');\nif (el) {\n  scrollToMessage(el);\n} else {\n  showNotice('Message not found in this conversation');\n}","handlingStrategy":"retry","validationCode":"const exists = this.conversations.some(c =>\n  c.messages?.some(m => m.id === messageId));\nif (!exists) { showNotice('Message not found'); return; }","typeGuard":"const isMessageElement = (el) =>\n  el instanceof HTMLElement && el.dataset.messageId != null;","tryCatchPattern":"try { await scrollToMessageById(id); } catch { showNotice('Could not locate that message'); }","preventionTips":["Validate the message ID against loaded data before attempting to scroll","Use consistent ID formatting between API data and DOM element attributes","Bound the retry loop and surface a user-visible message when it gives up"],"tags":["dom","scrolling","lazy-loading","deep-link"],"backgroundTag":"element-not-found","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}