Skip to content

bug: Pre-chat form submission discards pending conversation custom attributes set via SDK #15787

Description

@Thiteago

Describe the bug

When custom conversation attributes are queued via the JS SDK before a conversation exists (window.$chatwoot.setConversationCustomAttributes({...}) called right after "chatwoot:ready", with no active conversation yet), they are silently lost when the visitor's first message is submitted through the pre-chat form.

Root cause: PreChatForm.vue's onSubmit() calls this.clearConversations() (which resets conversation/pendingCustomAttributes to {}) before dispatching conversation/createConversation. The createConversation action only sends whatever customAttributes was explicitly passed in from the form (conversationCustomAttributes, from pre-chat custom fields), it never reads pendingCustomAttributes from state, unlike sendMessage/sendMessageWithData and sendAttachment, which do merge in pendingCustomAttributes/pendingLabels for every message after the first one.

So conversation custom attributes set via the SDK survive if the visitor's inbox has no pre-chat form (first message goes through the plain sendMessage path once the conversation already exists client-side), but are dropped whenever a pre-chat form is enabled, which is the default/common setup.

To Reproduce

  1. Enable "Pre Chat Form" on a Website inbox.
  2. Embed the widget and, before opening it, run:
    window.addEventListener('chatwoot:ready', () => { window.$chatwoot.setConversationCustomAttributes({ referral_code: 'ABC123' }); });
  3. Open the chat bubble → click "Start Conversation" → fill the pre-chat
    form (name + message) → submit.
  4. Open the created conversation in the agent dashboard.
  5. Check "Conversation Information" → the referral_code custom attribute
    (already registered in Settings > Custom Attributes, scope Conversation)
    is empty.

Expected behavior

Conversation custom attributes queued via window.$chatwoot.setConversationCustomAttributes() before the conversation exists should still be attached to the conversation once it's created via the pre-chat form, the same way they'd be attached to the second message sent in that conversation.

Environment

Docker

Cloud Provider

DigitalOcean

Platform

Browser

Operating system

Windows 11

Browser and version

Chrome 153

Docker (if applicable)

No response

Additional context

Confirmed in the current develop branch source (app/javascript/widget/store/modules/conversation/actions.js and
app/javascript/widget/views/PreChatForm.vue) , not fixed in the latest version. Happy to open a PR with the fix (already have a working patch + test in my fork).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions