Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/sdk/react/__tests__/client/LDReactClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ it('returns getInitializationState() === "initializing" initially', () => {
expect(client.getInitializationState()).toBe('initializing');
});

it('passes the eventSource option to the base client unmodified', () => {
const { mock } = makeMockBaseClient();
(createBaseClient as jest.Mock).mockReturnValue(mock);
const eventSource = {
createEventSource: jest.fn(),
capabilities: { readTimeout: true, customMethod: true, headers: true },
};

createClient('test-id', { kind: 'user', key: 'u1' }, { eventSource });

expect(createBaseClient).toHaveBeenLastCalledWith(
'test-id',
{ kind: 'user', key: 'u1' },
expect.objectContaining({ eventSource }),
);
});

it('sets initializedState to "complete" after start() resolves', async () => {
const { mock, resolveStart } = makeMockBaseClient();
(createBaseClient as jest.Mock).mockReturnValue(mock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ describe('createLDReactProvider (convenience factory)', () => {
);
});

it('passes the eventSource option to createClient unmodified', () => {
const eventSource = {
createEventSource: jest.fn(),
capabilities: { readTimeout: true, customMethod: true, headers: true },
};
createLDReactProvider('sdk-key', { kind: 'user', key: 'u1' }, { ldOptions: { eventSource } });

const clientOptions = (createClient as jest.Mock).mock.calls[0][2];
expect(clientOptions.eventSource).toBe(eventSource);
});

it('does not forward deferInitialization/startOptions/reactContext to createClient', () => {
const reactContext = initLDReactContext();
const startOptions = { timeout: 3 };
Expand Down
21 changes: 19 additions & 2 deletions packages/sdk/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
"default": "./dist/index.cjs"
}
},
"./fetch-eventsource": {
"import": {
"types": "./dist/fetch-eventsource.d.ts",
"default": "./dist/fetch-eventsource.js"
},
"require": {
"types": "./dist/fetch-eventsource.d.cts",
"default": "./dist/fetch-eventsource.cjs"
}
},
"./server": {
"import": {
"types": "./dist/server.d.ts",
Expand All @@ -47,6 +57,13 @@
}
}
},
"typesVersions": {
"*": {
"fetch-eventsource": [
"./dist/fetch-eventsource.d.ts"
]
}
},
"files": [
"dist"
],
Expand All @@ -66,8 +83,8 @@
"typescript": "6.0.3"
},
"dependencies": {
"@launchdarkly/js-client-sdk": "^4.14.0",
"@launchdarkly/js-server-sdk-common": "^2.26.1"
"@launchdarkly/js-client-sdk": "4.14.0",
"@launchdarkly/js-server-sdk-common": "2.26.1"
},
"peerDependencies": {
"react": ">=18.0.0",
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/react/src/fetch-eventsource/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Optional `fetch()`-based EventSource for the React SDK's streaming connection.
*
* This entry point re-exports the browser SDK's `fetch-eventsource` entry. Pass
* `fetchBrowserEventSource` as the `eventSource` option to opt in. The native browser EventSource
* remains the default, and only an application that imports this entry pays for the alternative.
*
* The `@launchdarkly/eventsource` dependency is optional. If an install omits optional
* dependencies, install it directly before this entry point is imported.
*
* @packageDocumentation
*/
export { fetchBrowserEventSource } from '@launchdarkly/js-client-sdk/fetch-eventsource';
export type { LDEventSourceFactory } from '@launchdarkly/js-client-sdk/fetch-eventsource';
12 changes: 12 additions & 0 deletions packages/sdk/react/tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ export default defineConfig([
mangleProps(opts);
},
},
{
...sharedOptions,
entry: { 'fetch-eventsource': 'src/fetch-eventsource/index.ts' },
clean: false,
// Keep the browser SDK's entry as an import so `@launchdarkly/eventsource` stays an optional
// dependency of js-client-sdk and is not bundled or required from this package.
noExternal: sharedOptions.noExternal.filter((name) => name !== '@launchdarkly/js-client-sdk'),
external: ['@launchdarkly/js-client-sdk'],
esbuildOptions(opts) {
mangleProps(opts);
},
},
]);
4 changes: 4 additions & 0 deletions scripts/package-config-tests/baseline/attw.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"@launchdarkly/react-sdk | node10": "NoResolution",
"@launchdarkly/react-sdk | node16-cjs": "ok",
"@launchdarkly/react-sdk | node16-esm": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | bundler": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node10": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node16-cjs": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node16-esm": "ok",
"@launchdarkly/react-sdk/server | bundler": "ok",
"@launchdarkly/react-sdk/server | node10": "NoResolution",
"@launchdarkly/react-sdk/server | node16-cjs": "ok",
Expand Down
6 changes: 6 additions & 0 deletions scripts/package-config-tests/baseline/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
"@launchdarkly/react-sdk | esbuild-esm-node": "ok",
"@launchdarkly/react-sdk | import": "ok",
"@launchdarkly/react-sdk | require": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | esbuild-cjs-node": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | esbuild-esm-browser": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | esbuild-esm-neutral": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | esbuild-esm-node": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | import": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | require": "ok",
"@launchdarkly/react-sdk/server | esbuild-cjs-node": "ok",
"@launchdarkly/react-sdk/server | esbuild-esm-browser": "ok",
"@launchdarkly/react-sdk/server | esbuild-esm-neutral": "ok",
Expand Down
20 changes: 20 additions & 0 deletions scripts/package-config-tests/baseline/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,26 @@
"@launchdarkly/react-sdk | nodenext-esm | ts6.0.3": "ok",
"@launchdarkly/react-sdk | preserve | ts5.9.3": "ok",
"@launchdarkly/react-sdk | preserve | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | bundler | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | bundler | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | bundler | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node10 | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | node10 | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node10 | ts6.0.3": "TS5107",
"@launchdarkly/react-sdk/fetch-eventsource | node16-cjs | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | node16-cjs | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node16-cjs | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node16-esm | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | node16-esm | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | node16-esm | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-cjs | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-cjs | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-cjs | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-esm | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-esm | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | nodenext-esm | ts6.0.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | preserve | ts5.9.3": "ok",
"@launchdarkly/react-sdk/fetch-eventsource | preserve | ts6.0.3": "ok",
"@launchdarkly/react-sdk/server | bundler | ts5.0.4": "TS1165 TS1169 TS2304 TS2339 TS2502 TS2726",
"@launchdarkly/react-sdk/server | bundler | ts5.9.3": "ok",
"@launchdarkly/react-sdk/server | bundler | ts6.0.3": "ok",
Expand Down
Loading