Skip to content

Commit 7b6ac03

Browse files
authored
feat: add support for steaming in Vega OS (#974)
**Requirements** - [ ] I have added test coverage for new or changed functionality - [ ] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** Provide links to any issues in this repository or elsewhere relating to this pull request. **Describe the solution you've provided** Provide a clear and concise description of what you expect to happen. **Describe alternatives you've considered** Provide a clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context about the pull request here. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Handle streaming by parsing data in `onprogress` and using `onreadystatechange` only for state transitions, improving SSE behavior on Vega OS. > > - **React Native SSE (`EventSource.ts`)**: > - Add `XMLHttpRequest.onprogress` to parse streaming data during `LOADING` via `_handleEvent` and emit errors for non-2xx/3xx statuses. > - Update `onreadystatechange` to ignore `LOADING`, handle connection open, DONE reconnection, and error/retry flow. > - Enhance debug logging and inline docs to clarify separation of data vs. state handling (Vega OS compatibility). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 097ce65. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 8d57904 commit 7b6ac03

File tree

1 file changed

+33
-1
lines changed
  • packages/sdk/react-native/src/fromExternal/react-native-sse

1 file changed

+33
-1
lines changed

packages/sdk/react-native/src/fromExternal/react-native-sse/EventSource.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* 2. added onopen, onclose, onerror, onretrying functions.
66
* 3. modified dispatch to work with functions added in 2.
77
* 4. replaced all for of loops with foreach
8+
*
9+
* Additional changes:
10+
* 1. separated event handling to use onprogress for data changes
11+
* and onreadystatechange for status changes. This is to address
12+
* an issue with Vega OS where they do not fire a readyStatechange
13+
* event when the response is received.
814
*/
915
import type { EventSourceEvent, EventSourceListener, EventSourceOptions, EventType } from './types';
1016

@@ -132,8 +138,34 @@ export default class EventSource<E extends string = never> {
132138

133139
this._xhr.timeout = this._timeout;
134140

141+
this._xhr.onprogress = () => {
142+
if (this._status === this.CLOSED || this._xhr.readyState !== XMLHttpRequest.LOADING) {
143+
return;
144+
}
145+
146+
this._logger?.debug(
147+
`[EventSource][onprogress] ReadyState: ${
148+
XMLReadyStateMap[this._xhr.readyState] || 'Unknown'
149+
}(${this._xhr.readyState}), status: ${this._xhr.status}`,
150+
);
151+
152+
if (this._xhr.status >= 200 && this._xhr.status < 400) {
153+
this._handleEvent(this._xhr.responseText || '');
154+
} else {
155+
this._status = this.ERROR;
156+
157+
this.dispatch('error', {
158+
type: 'error',
159+
message: this._xhr.responseText,
160+
xhrStatus: this._xhr.status,
161+
xhrState: this._xhr.readyState,
162+
});
163+
}
164+
};
165+
135166
this._xhr.onreadystatechange = () => {
136-
if (this._status === this.CLOSED) {
167+
// Do not handle this state if the status is loading as we will delegate this to the onprogress listener.
168+
if (this._status === this.CLOSED || this._xhr.readyState === XMLHttpRequest.LOADING) {
137169
return;
138170
}
139171

0 commit comments

Comments
 (0)