Skip to content

chore: Add an example for the browser SDK custom EventSource option - #2139

Open
joker23 wants to merge 2 commits into
mainfrom
skz/sdk-3151/custom-eventsource-example
Open

joker23 wants to merge 2 commits into
mainfrom
skz/sdk-3151/custom-eventsource-example

Conversation

@joker23

@joker23 joker23 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a vanilla-TypeScript browser example that demonstrates the injectable eventSource option. The example passes fetchBrowserEventSource (from @launchdarkly/js-client-sdk/fetch-eventsource) so that usePost: true takes effect for the streaming connection, and enables the FDv2 data system.

The example was split out of #2033 to reduce the review load there. This PR is stacked on #2033 and shows only the example diff; it retargets to main when #2033 merges. Besides the example directory, it adds the workspace entry in the root package.json and the release-please version-pin entry for the example's SDK dependency.


Note

Overview
Adds a new workspace @launchdarkly/browser-example-custom-eventsource that shows how to wire fetchBrowserEventSource from @launchdarkly/js-client-sdk/fetch-eventsource with usePost: true and FDv2 (dataSystem: {}) so streaming uses POST instead of native GET-only EventSource.

The example includes build/docs (.env.template, README), a Playwright check that the flag evaluates to true and a POST hits /sdk/stream/eval, and tsdown bundling that inlines the fetch-eventsource subpath for a single script tag.

Repo wiring: registers the path in the root package.json workspaces, adds a release-please pin for the example’s SDK dependency, and a run-custom-eventsource-example job in .github/workflows/browser.yml (same fork/OIDC guard as the existing browser example job).

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

Base automatically changed from skz/sdk-3151/common-eventsource-node-consumers to main October 30, 2026 22:34
joker23 added a commit that referenced this pull request Oct 30, 2026
…2033)

## Summary

Adds an opt-in `fetch()`-based `EventSource` to the browser SDK behind
its own `@launchdarkly/js-client-sdk/fetch-eventsource` entry point, so
neither the implementation nor its dependency reaches the default
bundle. The native browser `EventSource` remains the default. Includes
the `eventSource` factory option plumbing. The example app moved to
#2139 to keep this diff smaller.

The browser contract-test entity can be opened with
`?eventsource=fetch`, which makes every client use the fetch-based
`EventSource` and advertise the `client-use-post` and
`client-event-source-http-errors` capabilities. CI runs the fetch entity
against both harnesses. The v2 run (with
`suppressions_fetch_eventsource.txt`) covers the FDv1 path, including
`REPORT` streaming and the poll tags header tests; the stream tags
assertions are skipped because the transport strips the tags header. The
v3 run (with `suppressions_datamode_changes.txt`) covers the FDv2 path,
including the `usePost` POST streaming variants.

The transport does not send the `x-launchdarkly-tags` header. The
streaming service's CORS allow-list does not include it, and the browser
preflight would fail.

Replaces #2034 and #2048, which GitHub auto-marked merged during a stack
reorder; their bot-review history lives there.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Adds an optional **`@launchdarkly/js-client-sdk/fetch-eventsource`**
subpath and **`eventSource`** client option so apps can stream with a
**`fetch()`-based EventSource** instead of the native one, without
pulling **`@launchdarkly/eventsource`** into the default bundle.
**`BrowserRequests`** delegates creation to the configured factory and
exposes **capabilities** (headers, custom method, read timeout) so
**REPORT** / **POST** streaming can be enabled when the transport
supports them; **`fetchBrowserEventSource`** strips
**`x-launchdarkly-tags`** on stream requests to avoid CORS preflight
failures.
> 
> **CI and contract tests** restart the browser entity with
**`?eventsource=fetch`**, run extra harness passes (FDv1/FDv2, native vs
fetch), and split skip lists (**`suppressions_fetch_eventsource.txt`**,
tightened **`suppressions_datamode_changes.txt`**). The entity
advertises **`client-use-post`** and
**`client-event-source-http-errors`** in fetch mode and maps
**`usePost`** from harness config.
> 
> **`StreamingFDv2Base`** now classifies status-less filter failures as
network errors, dedupes filter vs **`onerror`** for the same event
object, and adds tests for those paths. React CI switches contract-test
installs to **`yarn workspaces focus`**. Package-config baselines cover
the new export.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
6b2eac2. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@joker23
joker23 force-pushed the skz/sdk-3151/custom-eventsource-example branch from 652fbeb to 8a23d46 Compare October 30, 2026 22:34
@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 32220 bytes
Compressed size limit: 32500
Uncompressed size: 152548 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26066 bytes
Compressed size limit: 44000
Uncompressed size: 168326 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 34404 bytes
Compressed size limit: 35000
Uncompressed size: 122974 bytes

@joker23
joker23 marked this pull request as ready for review October 30, 2026 22:48
@joker23
joker23 requested a review from a team as a code owner October 30, 2026 22:48

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
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.

1 participant