Skip to content

feat: Add an eventSource option that supplies the SSE client used for streaming - #358

Merged
joker23 merged 9 commits into
mainfrom
skz/sdk-3441/sse-client-factory
Nov 12, 2026
Merged

joker23 merged 9 commits into
mainfrom
skz/sdk-3441/sse-client-factory

Conversation

@joker23

@joker23 joker23 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds eventSource to LDCommonConfig, an optional SseClientBuilder. When it is null, the SDK uses the default client for the platform. On web, that is the browser EventSource, which cannot send a request body or report an HTTP error. An app passes SSEClient.http to stream with fetch() instead, so useReport and usePost work on web. On other platforms the default client is already SSEClient.http.
  • The app passes the implementation, so a web build that leaves the option null never references the HTTP SSE client and the compiler removes it. A runtime bool would keep both clients reachable. Measured with dart compile js -O2 against common_client: 324 KB without the option, 354 KB with SSEClient.http.
  • SSEClient and SseClientBuilder are exported from common_client. No other SSE type is exported.
  • A supplied builder is treated as able to send POST and REPORT. Without one, useReport on web falls back to GET with a warning, and usePost on web skips the streaming sources and polls, as before.
  • On web, the SDK drops the application tags header from the streaming request. The CORS allow-list of the streaming service does not include it. The unused streamingReportSupported platform getters are removed.
  • FDv1 streaming uses the client-side ID as the environment ID when the connect headers are present but lack it, as happens after CORS filtering.
  • Both streaming data sources build their client through the same builder type, so tests inject a fake client the same way on both paths.
  • Adds a Chrome test file for the web-only decisions and a CI step that runs it with dart test -p chrome.

Additional context

This PR moves the exact pin of launchdarkly_event_source_client in common_client from 3.0.1 to 3.1.0, which ships SSEClient.http.

This PR is the bottom of a stack. #359 and #360 build on it.

Related tickets

  • sdk-3441

Note

Overview
Adds LDCommonConfig.eventSource, an optional SseClientBuilder, and wires it through FDv1 StreamingDataSource and FDv2 FDv2DataSystem so apps can supply SSEClient.http on web and enable POST/REPORT streaming instead of default browser GET or polling fallbacks.

Introduces streaming_client.dart with shared streamingRequestHeaders (drops x-launchdarkly-tags on web for CORS) and streamingCustomMethodSupported to decide POST/REPORT vs fallbacks. Platform defaults replace streamingReportSupported with streamingPostSupported and streamingTagsHeaderSupported. FDv1 streaming now falls back to the client-side ID for environment ID when connect headers omit it after CORS filtering.

Exports SseClientBuilder and SSEClient, bumps launchdarkly_event_source_client to 3.1.0, and adds Chrome CI plus VM/browser tests for web-only streaming behavior.

Reviewed by Cursor Bugbot for commit 1cfae3d. Bugbot is set up for automated code reviews on this repo. Configure here.

@joker23
joker23 added this pull request to stack #361 November 2, 2026 20:17
@joker23
joker23 force-pushed the skz/sdk-3441/sse-client-factory branch 3 times, most recently from e161c65 to 7896553 Compare November 4, 2026 19:16
@joker23
joker23 marked this pull request as ready for review November 5, 2026 15:39
@joker23
joker23 requested a review from a team as a code owner November 5, 2026 15:39
devin-ai-integration[bot]

This comment was marked as resolved.

@joker23
joker23 marked this pull request as draft November 5, 2026 16:42
@joker23
joker23 force-pushed the skz/sdk-3441/sse-client-factory branch from 128eff9 to 2c30ca9 Compare November 5, 2026 18:02
@joker23 joker23 changed the title feat: Add a public SSE client factory option feat: Add an option to stream with the HTTP SSE client on web Nov 5, 2026
@joker23
joker23 force-pushed the skz/sdk-3441/sse-client-factory branch 2 times, most recently from c298b80 to d4c9d97 Compare November 5, 2026 20:50
@joker23
joker23 marked this pull request as ready for review November 5, 2026 22:47

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

Devin Review

@devin-ai-integration devin-ai-integration Bot Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Ping polls fail after REPORT fallback

On web without HTTP streaming, useReport makes the stream fall back to GET, but _requestor also uses GET. Requestor still selects the REPORT polling path, so ping polls omit the context body and fail.

Learn more

A ping event asks Requestor to fetch all flags using the polling configuration, independently of the stream's HTTP method. When the browser stream falls back from REPORT to GET, _useReport becomes false, but pollingDataSourceConfig.useReport stays true. Requestor chooses the REPORT polling path from that config, while the new method and context select GET; the request carries no context for the REPORT endpoint.

Example: On web, configure FDv1 useReport: true and leave useHttpStreamingOnWeb: false. A ping triggers GET /msdk/evalx/context without a body instead of REPORT /msdk/evalx/context with the JSON context.

Recommended fix: Give Requestor the context encoding and RequestMethod derived from pollingDataSourceConfig.useReport, not _useReport. Keep the GET fallback limited to the streaming URI, body, and method. Add a browser ping-poll regression test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing on trunk (same _useReport fallback and Requestor construction). Kept out of this PR to keep the diff scoped. Tracked in SDK-3484.

@devin-ai-integration devin-ai-integration Bot Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Stopped streams leave SSE clients open

When a stream stops, stop() cancels its listener but never closes _client. Each context switch leaves the client's control streams open instead of releasing its resources.

Learn more

The streaming data source owns the SSE client it creates on start(). Canceling the subscription stops the active connection, but HttpSseClient.close also closes its internal controllers; the cancellation path does not do that. DataSourceManager invokes stop() whenever it replaces a source, so an application that identifies multiple contexts leaves each previous SSE client unclosed.

Example: Identify user A, then user B, then user C in streaming mode. Each old source cancels its subscription, but neither A's nor B's SSE client receives close().

Recommended fix: Close the owned SSE client on stop(), clear _client, and handle asynchronous close failures without letting them escape the synchronous stop path.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing on trunk (stop() only cancels the subscription there too). Deferred to keep this PR scoped. Tracked in SDK-3485.

@joker23 joker23 changed the title feat: Add an option to stream with the HTTP SSE client on web feat: Add an eventSource option that supplies the SSE client used for streaming Nov 9, 2026
Base automatically changed from skz/sdk-3440/http-sse-client-web to main November 10, 2026 20:21
@joker23
joker23 force-pushed the skz/sdk-3441/sse-client-factory branch from ec58405 to 4a58c8b Compare November 10, 2026 20:21
@joker23
joker23 force-pushed the skz/sdk-3441/sse-client-factory branch from 4a58c8b to 1cfae3d Compare November 10, 2026 20:44
@joker23
joker23 merged commit b1e0b13 into main Nov 12, 2026
10 checks passed
@joker23
joker23 deleted the skz/sdk-3441/sse-client-factory branch November 12, 2026 16:48
joker23 pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.16.0](launchdarkly_common_client-v1.15.1...launchdarkly_common_client-v1.16.0)
(2026-11-12)


### Features

* Add an eventSource option that supplies the SSE client used for
streaming
([#358](#358))
([b1e0b13](b1e0b13))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Release PR** that publishes `launchdarkly_common_client` **1.16.0**
via Release Please: bumps the package version in `pubspec.yaml`, updates
`.release-please-manifest.json`, and adds a changelog entry for this
release.
> 
> The changelog records the shipped feature from
[#358](#358):
an **`eventSource`** configuration option so callers can supply the SSE
client used for FDv2 streaming (defaulting to the built-in client when
omitted). No runtime code changes appear in this diff—only release
bookkeeping.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a7b18cc. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants