-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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
- PR: fix: ws connection mutex #1356
- Comment: fix: ws connection mutex #1356 (comment)
- Requested by: @marrouchi
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request