Skip to content

Commit 16376fe

Browse files
LaunchDarklyReleaseBotyusintobwoskow-ldeli-darklyLaunchDarklyCI
authoredApr 15, 2022
prepare 2.25.2 release (#131)
* Initial commit * Delete extraneous files from lib. * Update initLDClient.test.ts * Update withLDProvider.tsx (#18) * update JS SDK dependency to 2.16.3 * use JS SDK 2.17.0 * improve tests to clarify which options we're passing in and which ones are added by the wrapper * set wrapperName to react-client-sdk * lint * Update withLDProvider.test.tsx * update JS SDK to 2.17.5 + a few dev dependency bumps (#21) * downgrade typescript to 3.8.3 (#22) * [Fixes for] Expose LDProvider as a standalone component (#31) * remove startsWith usage (#23) * Fix the broken build (#24) * Expose ld provider (#40) * Add tests for the LDProvider * Add LDProvider component * Add LDProvider to main export * Update provider tests * Remove unused EnhancedComponent * Abstract function to generate react options * add waitForUserToInitializeClient flag to Provider * rename to LDProvider.tsx * fix tests * remove async from componentDidMount * fixes from CR * add test * cleanup * update types for componentDidUpdate * await initLDClient Co-authored-by: Nicholas Mitchell <nicholas@netlify.com> Co-authored-by: Martin Heller <mheller@testo.de> * update to JS SDK 2.18.0 (adds disableSyncEventPost) (#25) * 45 fix providers to respect subscribed flags (#46) * Fixed asyncWithLDProvider.tsx and provider.tsx so that they only provide flag changes for subscribed flags. * Removed unused imports. * Addressed PR feedback. Fixed linting errors. Co-authored-by: Clay Embry <cembry@atlassian.com> * targetflags simplified logic (#26) * remove client-side ids from examples (#27) * update JS SDK to 2.18.1 * Fixing camelCaseKeys export (#44) * new js-common-sdk version (#30) * adding alias functionality (#31) * pin typedoc to unblock our releases (#32) * Removed the guides link * add inlineUsersToEvents to TypeScript defs by updating js-client-sdk (#33) * debugging * Fix linting errors * [ch103643] Fix examples to use local sdk * Remove unwanted changes. * Update package.json * Update yarn.lock * Update lock files. * Update package-lock.json * Update package-lock.json * Update package.json * Update link-dev.sh Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> * Update link-dev.sh * Update yarn.lock * Add react 17 peer dep (#61) * Update common JS SDK library to use fixes for debug event generation issues. (#36) * HOC static hoisting (#71) * Added a test for hoisting react statics in withLDProvider HOC * Fixed linting errors * Fixed more linting errors * update example app deps (#38) * Updated asyncWithLDProvider to fetch latest flag values when the Provider renders (#39) * Updated asyncWithLDProvider to fetch latest flag values when the Provider renders * Fixed linting * Updates docs URLs * fix: improve types of withLDProvider (#97) * [sc-107070] Include src for sourcemaps to work * [sc-127032] Omit deferInitialization from asyncWithLDProvider config * Removed and ignored lock files. * Update types.ts * Update typescript version (#44) * Update Makefile * Update Makefile * Deleting test-types.ts (#45) * [sc-132394] Add typedoc for AsyncProviderConfig (#47) Co-authored-by: Molly <molly.jones@launchdarkly.com> * Pass in client (#105) * [sc134057] Fix react sdk lint errors (#48) * remove custom TypeDoc build, use Releaser's standard logic (#49) * update js-client-sdk to 2.20.1 for localstorage error-handling fix and others * export more public symbols from entry point * [sc134364] Upgrade typescript, tslint and jest. (#50) Co-authored-by: Eli Bishop <eli@launchdarkly.com> * update js-client-sdk to 2.20.2 for sc-142333 fix (#53) * First commit. TODO: migrate enzyme to rtl. * Removed enzyme. Fixed prettier parentheses rule. * Fixed broken snapshot tests. Removed unused imports. * Update package.json Co-authored-by: Yusinto Ngadiman <yusinto@gmail.com> Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> Co-authored-by: Eli Bishop <eli@launchdarkly.com> Co-authored-by: LaunchDarklyCI <dev@launchdarkly.com> Co-authored-by: Martin Heller <github@technopolis.de> Co-authored-by: Ben Woskow <bwoskow@launchdarkly.com> Co-authored-by: bezreyhan <bezreyhan@gmail.com> Co-authored-by: Nicholas Mitchell <nicholas@netlify.com> Co-authored-by: Martin Heller <mheller@testo.de> Co-authored-by: clayembry <clayembry@yahoo.com> Co-authored-by: Clay Embry <cembry@atlassian.com> Co-authored-by: Jonathan Felchlin <jonathan@xgecko.com> Co-authored-by: Mac Lockard <maclockard@gmail.com> Co-authored-by: Gavin Whelan <gwhelan@launchdarkly.com> Co-authored-by: Nathan Waddell <45477581+NathanWaddell121107@users.noreply.github.com> Co-authored-by: Clifford Tawiah <ctawiah@launchdarkly.com> Co-authored-by: Cliff Tawiah <82856282+ctawiah@users.noreply.github.com> Co-authored-by: LaunchDarklyReleaseBot <launchdarklyreleasebot@launchdarkly.com> Co-authored-by: Ember Stevens <ember.stevens@launchdarkly.com> Co-authored-by: ember-stevens <79482775+ember-stevens@users.noreply.github.com> Co-authored-by: Derek Sifford <dereksifford@gmail.com> Co-authored-by: Jaz White <jwhite@launchdarkly.com> Co-authored-by: Molly <molly.jones@launchdarkly.com> Co-authored-by: Tim Lee <tim.lee@red-badger.com> Co-authored-by: Louis Chan <91093020+louis-launchdarkly@users.noreply.github.com> Co-authored-by: Louis Chan <lchan@launchdarkly.com>
1 parent 611a82c commit 16376fe

8 files changed

+35
-42
lines changed
 

‎.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"singleQuote": true,
33
"trailingComma": "all",
4-
"printWidth": 120
4+
"printWidth": 120,
5+
"arrowParens": "always"
56
}

‎package.json

+10-13
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,24 @@
3737
},
3838
"homepage": "https://github.com/launchdarkly/react-client-sdk",
3939
"devDependencies": {
40-
"@testing-library/jest-dom": "^5.16.1",
41-
"@testing-library/react": "^12.1.2",
42-
"@types/enzyme": "^3.10.3",
40+
"@testing-library/jest-dom": "^5.16.4",
41+
"@testing-library/react": "^13.0.1",
4342
"@types/hoist-non-react-statics": "^3.3.1",
4443
"@types/jest": "^27.0.3",
4544
"@types/lodash.camelcase": "^4.3.6",
4645
"@types/prop-types": "^15.7.4",
47-
"@types/react": "^17.0.37",
48-
"@types/react-dom": "^17.0.11",
49-
"@types/react-test-renderer": "^17.0.1",
46+
"@types/react": "^18.0.3",
47+
"@types/react-dom": "^18.0.0",
48+
"@types/react-test-renderer": "^18.0.0",
5049
"@types/uuid": "^3.4.5",
51-
"enzyme": "^3.10.0",
52-
"enzyme-adapter-react-16": "^1.14.0",
5350
"jest": "^27.4.4",
5451
"jest-environment-jsdom-global": "^3.0.0",
5552
"jest-junit": "^13.0.0",
5653
"prettier": "^1.18.2",
5754
"prop-types": "^15.7.2",
58-
"react": "^17.0.0",
59-
"react-dom": "^17.0.0",
60-
"react-test-renderer": "^17.0.2",
55+
"react": "^18.0.0",
56+
"react-dom": "^18.0.0",
57+
"react-test-renderer": "^18.0.0",
6158
"rimraf": "^3.0.0",
6259
"ts-jest": "^27.1.1",
6360
"tslint": "^6.1.3",
@@ -72,7 +69,7 @@
7269
"uuid": "^3.3.2"
7370
},
7471
"peerDependencies": {
75-
"react": "^16.6.3 || ^17.0.0",
76-
"react-dom": "^16.8.4 || ^17.0.0"
72+
"react": "^16.6.3 || ^17.0.0 || ^18.0.0",
73+
"react-dom": "^16.8.4 || ^17.0.0 || ^18.0.0"
7774
}
7875
}

‎setupTests.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
const enzyme = require('enzyme');
2-
const Adapter = require('enzyme-adapter-react-16');
31
require('@testing-library/jest-dom/extend-expect');
4-
5-
enzyme.configure({ adapter: new Adapter() });

‎src/asyncWithLDProvider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const renderWithConfig = async (config: AsyncProviderConfig) => {
3030

3131
const { getByText } = render(
3232
<LDProvider>
33-
<Consumer>{value => <span>Received: {JSON.stringify(value.flags)}</span>}</Consumer>
33+
<Consumer>{(value) => <span>Received: {JSON.stringify(value.flags)}</span>}</Consumer>
3434
</LDProvider>,
3535
);
3636

‎src/asyncWithLDProvider.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, FunctionComponent } from 'react';
1+
import React, { useState, useEffect, ReactNode } from 'react';
22
import { LDFlagSet, LDFlagChangeset } from 'launchdarkly-js-client-sdk';
33
import { AsyncProviderConfig, defaultReactOptions } from './types';
44
import { Provider } from './context';
@@ -34,7 +34,7 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
3434
const reactOptions = { ...defaultReactOptions, ...userReactOptions };
3535
const { ldClient } = await initLDClient(clientSideID, user, reactOptions, options, targetFlags);
3636

37-
const LDProvider: FunctionComponent = ({ children }) => {
37+
const LDProvider = ({ children }: { children: ReactNode }) => {
3838
const [ldData, setLDData] = useState({
3939
flags: fetchFlags(ldClient, reactOptions, targetFlags),
4040
ldClient,
@@ -45,14 +45,14 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
4545
const { bootstrap } = options;
4646
if (bootstrap && bootstrap !== 'localStorage') {
4747
const bootstrappedFlags = reactOptions.useCamelCaseFlagKeys ? camelCaseKeys(bootstrap) : bootstrap;
48-
setLDData(prev => ({ ...prev, flags: bootstrappedFlags }));
48+
setLDData((prev) => ({ ...prev, flags: bootstrappedFlags }));
4949
}
5050
}
5151

5252
ldClient.on('change', (changes: LDFlagChangeset) => {
5353
const flattened: LDFlagSet = getFlattenedFlagsFromChangeset(changes, targetFlags, reactOptions);
5454
if (Object.keys(flattened).length > 0) {
55-
setLDData(prev => ({ ...prev, flags: { ...prev.flags, ...flattened } }));
55+
setLDData((prev) => ({ ...prev, flags: { ...prev.flags, ...flattened } }));
5656
}
5757
});
5858
}, []);

‎src/initLDClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const initLDClient = async (
2525
const allOptions = { wrapperName: 'react-client-sdk', wrapperVersion: version, ...options };
2626
const ldClient = ldClientInitialize(clientSideID, user, allOptions);
2727

28-
return new Promise<AllFlagsLDClient>(resolve => {
28+
return new Promise<AllFlagsLDClient>((resolve) => {
2929
ldClient.on('ready', () => {
3030
const flags = fetchFlags(ldClient, reactOptions, targetFlags);
3131
resolve({ flags, ldClient });

‎src/provider.test.tsx

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
jest.mock('./initLDClient', () => jest.fn());
22
jest.mock('./context', () => ({ Provider: 'Provider' }));
33

4-
import * as React from 'react';
4+
import React, { Component } from 'react';
55
import { create } from 'react-test-renderer';
6-
import { shallow } from 'enzyme';
76
import { LDClient, LDFlagChangeset, LDFlagSet, LDOptions, LDUser } from 'launchdarkly-js-client-sdk';
87
import initLDClient from './initLDClient';
98
import { LDReactOptions, EnhancedComponent, defaultReactOptions, ProviderConfig } from './types';
@@ -80,7 +79,7 @@ describe('LDProvider', () => {
8079
const user1: LDUser = { key: 'yus', name: 'yus ng' };
8180
const user2: LDUser = { key: 'launch', name: 'darkly' };
8281
const options: LDOptions = { bootstrap: {} };
83-
const ldClient: Promise<LDClient> = new Promise(async resolve => {
82+
const ldClient: Promise<LDClient> = new Promise(async (resolve) => {
8483
resolve((await initLDClient(clientSideID, user1, defaultReactOptions, options, undefined)).ldClient);
8584

8685
return;
@@ -101,7 +100,7 @@ describe('LDProvider', () => {
101100
test('ld client is created if passed in promise resolves as undefined', async () => {
102101
const user: LDUser = { key: 'yus', name: 'yus ng' };
103102
const options: LDOptions = { bootstrap: {} };
104-
const ldClient: Promise<undefined> = new Promise(async resolve => {
103+
const ldClient: Promise<undefined> = new Promise(async (resolve) => {
105104
resolve(undefined);
106105

107106
return;
@@ -129,8 +128,8 @@ describe('LDProvider', () => {
129128
<App />
130129
</LDProvider>
131130
);
132-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
133-
const initialState = component.state() as HocState;
131+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
132+
const initialState = component.state as HocState;
134133

135134
expect(initialState.flags).toEqual({});
136135
});
@@ -154,8 +153,8 @@ describe('LDProvider', () => {
154153
<App />
155154
</LDProvider>
156155
);
157-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
158-
const initialState = component.state() as HocState;
156+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
157+
const initialState = component.state as HocState;
159158

160159
expect(mockInitLDClient).not.toHaveBeenCalled();
161160
expect(initialState.flags).toEqual({ testFlag: true, anotherTestFlag: false });
@@ -178,8 +177,8 @@ describe('LDProvider', () => {
178177
<App />
179178
</LDProvider>
180179
);
181-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
182-
const initialState = component.state() as HocState;
180+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
181+
const initialState = component.state as HocState;
183182

184183
expect(mockInitLDClient).not.toHaveBeenCalled();
185184
expect(initialState.flags).toEqual({ 'test-flag': true, 'another-test-flag': false });
@@ -200,8 +199,8 @@ describe('LDProvider', () => {
200199
<App />
201200
</LDProvider>
202201
);
203-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
204-
const initialState = component.state() as HocState;
202+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
203+
const initialState = component.state as HocState;
205204

206205
expect(mockInitLDClient).not.toHaveBeenCalled();
207206
expect(initialState.flags).toEqual({ testFlag: true, anotherTestFlag: false });
@@ -221,8 +220,8 @@ describe('LDProvider', () => {
221220
<App />
222221
</LDProvider>
223222
);
224-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
225-
const initialState = component.state() as HocState;
223+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
224+
const initialState = component.state as HocState;
226225

227226
expect(mockInitLDClient).not.toHaveBeenCalled();
228227
expect(initialState.flags).toEqual({ testFlag: true, anotherTestFlag: false });
@@ -239,8 +238,8 @@ describe('LDProvider', () => {
239238
<App />
240239
</LDProvider>
241240
);
242-
const component = shallow(LaunchDarklyApp, { disableLifecycleMethods: true });
243-
const initialState = component.state() as HocState;
241+
const component = create(LaunchDarklyApp).toTree()?.instance as Component;
242+
const initialState = component.state as HocState;
244243

245244
expect(mockInitLDClient).not.toHaveBeenCalled();
246245
expect(initialState.flags).toEqual({});

‎src/provider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import React, { Component, PropsWithChildren } from 'react';
22
import { LDClient, LDFlagSet, LDFlagChangeset } from 'launchdarkly-js-client-sdk';
33
import { EnhancedComponent, ProviderConfig, defaultReactOptions } from './types';
44
import { Provider, LDContext as HocState } from './context';
@@ -22,7 +22,7 @@ import { camelCaseKeys, fetchFlags, getFlattenedFlagsFromChangeset } from './uti
2222
* within your application. This provider is used inside the `withLDProviderHOC` and can be used instead to initialize
2323
* the `launchdarkly-js-client-sdk`. For async initialization, check out the `asyncWithLDProvider` function
2424
*/
25-
class LDProvider extends React.Component<ProviderConfig, HocState> implements EnhancedComponent {
25+
class LDProvider extends Component<PropsWithChildren<ProviderConfig>, HocState> implements EnhancedComponent {
2626
readonly state: Readonly<HocState>;
2727

2828
constructor(props: ProviderConfig) {

0 commit comments

Comments
 (0)
Please sign in to comment.