In SSE mode, loading may end too early
Fabilin opened this issue · 0 comments
When using Server-Sent Events to transmit messages, the tock-react-kit
assumes all messages in a response have been processed by the time the POST response is received. However, because TOCK's server-sent events are sent concurrently to the POST response, there is no guarantee of that being the case. This is especially an issue for custom user interfaces that need a way to tell whether the chat is expecting more messages.
Diagnosis: Sequence diagram
sequenceDiagram
actor user
participant TRK as tock-react-kit
participant TOCK as TOCK Backend
user->>TRK: message
TRK-->>user: <loading starts>
TRK->>TOCK: <send message>
par
TOCK->>TRK: POST answer
TRK-->>user: <loading ends>
and
TOCK->>TRK: SSE answer
TRK->>user: Display answer
end
Proposed Solution
We could make it so when the POST response is received before the first SSE message for that response, it gets processed immediately and the late SSE messages are discarded. This would also have the benefit of ensuring messages do not get lost when the SSE connection is lost at the same time a user sends a message.
This would however require an update to the TOCK backend, to allow linking responses from SSE and POST.