QuickReply scroll-to-new-post fails - onInsert callback receives wrong parameter

Itworx4me

Well-known member
Affected version
XenForo 2.3.7
In js/xf/message.js, the XF.Message.insertMessages function passes the wrong parameter to the onInsert callback, causing the scroll-to-new-post feature in QuickReply to fail silently.

Location: js/xf/message.js - XF.Message.insertMessages function
The Problem: The callback is invoked with html instead of messages:
Code:
if (onInsert)
{
    onInsert(html)  // Wrong - passes raw html parameter
}
But XF.QuickReply.insertMessages expects an array:

Code:
messages =>
{
    const message = messages[0]  // Expects array, receives DOM element/fragment
    if (message)
    {
        const dims = XF.dimensions(message)
        // ... scroll logic
    }
}

Additional Issue: When the response contains whitespace, messages[0] can be a text node (whitespace) rather than an element, which also causes XF.dimensions() to fail.
Expected Behavior: After posting a quick reply, the page should scroll to the new post.
Actual Behavior: The new post is inserted but no scrolling occurs.

Suggested Fix:
Code:
// Filter to element nodes only
messages = messages.filter(node => node.nodeType === Node.ELEMENT_NODE)

// ... existing forEach logic ...

if (onInsert)
{
    onInsert(messages)  // Pass the messages array, not html
}
 
Back
Top Bottom