Skip to content

Improve chat widget cross-tab synchronization for subscription events #1362

@coderabbitai

Description

@coderabbitai

Problem Description

The chat widget uses the Broadcast Channel API to notify other browser tabs when a user has subscribed (submitted the form) to start the chat. However, there's a race condition where other tabs could reload before the chatbot responds with the initial "Get Started" message.

Current Implementation

Currently, we use a timeout workaround in the sendGetStarted function:

// Notify other tabs that we've subscribed and sent the 1st msg (so they reload)
setTimeout(() => {
  postMessage({ event: "subscribed" });
}, 500);

Issue

The 500ms timeout is arbitrary and doesn't guarantee that the chatbot has responded with the initial message. This can lead to:

  • Race conditions where tabs reload too early
  • Inconsistent user experience across tabs
  • Potential loss of the initial bot response

Desired Solution

Find a better way to synchronize cross-tab communication that doesn't rely on arbitrary timeouts. Possible approaches:

  • Wait for the actual bot response before broadcasting
  • Use a more sophisticated event-driven approach
  • Implement proper state synchronization mechanisms

Context

This affects the chat widget's multi-tab functionality and user experience consistency.

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions