Skip to content

Commit 9058c26

Browse files
Merge branch 'development' into release_v1.9.0
2 parents 32bcb78 + 9de128c commit 9058c26

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/SplitClient.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class SplitComponent extends React.Component<IUpdateProps & { factory: Sp
2626
static getDerivedStateFromProps(props: ISplitClientProps & { factory: SplitIO.IBrowserSDK | null, client: SplitIO.IBrowserClient | null }, state: ISplitContextValues) {
2727
const { client, factory, attributes } = props;
2828
// initAttributes can be called in the `render` method too, but it is better here for separation of concerns
29-
if (client) initAttributes(client, attributes);
29+
initAttributes(client, attributes);
3030
const status = getStatus(client);
3131
// no need to compare status.isTimedout, since it derives from isReady and hasTimedout
3232
if (client !== state.client ||
@@ -146,7 +146,7 @@ export function SplitClient(props: ISplitClientProps) {
146146
{(splitContext: ISplitContextValues) => {
147147
const { factory } = splitContext;
148148
// getSplitSharedClient is idempotent like factory.client: it returns the same client given the same factory, Split Key and TT
149-
const client = factory ? getSplitSharedClient(factory, props.splitKey, props.trafficType, props.attributes) : null;
149+
const client = factory ? getSplitSharedClient(factory, props.splitKey, props.trafficType) : null;
150150
return (
151151
<SplitComponent {...props} factory={factory} client={client} attributes={props.attributes} />
152152
);

src/SplitFactory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class SplitFactory extends React.Component<ISplitFactoryProps, { factory:
5353
}
5454
this.isFactoryExternal = propFactory ? true : false;
5555

56-
// Instantiate main client.
56+
// Instantiate main client. Attributes are set on `SplitComponent.getDerivedStateFromProps`
5757
const client = factory ? factory.client() : null;
5858

5959
this.state = {

src/useSplitClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function useSplitClient(key?: SplitIO.SplitKey, trafficType?: string, att
1717
const context = React.useContext(SplitContext);
1818
let { factory, client } = context;
1919
if (key && factory) {
20-
client = getSplitSharedClient(factory, key, trafficType, attributes);
20+
client = getSplitSharedClient(factory, key, trafficType);
2121
}
22-
if (client) initAttributes(client, attributes);
22+
initAttributes(client, attributes);
2323
return client === context.client ? context : {
2424
...context, client, ...(client as IClientWithContext).__getStatus()
2525
};

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function getSplitFactory(config: SplitIO.IBrowserSettings): IFactoryWithC
4444
}
4545

4646
// idempotent operation
47-
export function getSplitSharedClient(factory: SplitIO.IBrowserSDK, key: SplitIO.SplitKey, trafficType?: string, _attributes?: SplitIO.Attributes): IClientWithContext {
47+
export function getSplitSharedClient(factory: SplitIO.IBrowserSDK, key: SplitIO.SplitKey, trafficType?: string): IClientWithContext {
4848
// factory.client is an idempotent operation
4949
const client = factory.client(key, trafficType) as IClientWithContext;
5050
if ((factory as IFactoryWithClients).sharedClientInstances) {
@@ -127,8 +127,8 @@ export function validateFeatureFlags(maybeFeatureFlags: unknown, listName = 'spl
127127
/**
128128
* Manage client attributes binding
129129
*/
130-
export function initAttributes(client: SplitIO.IBrowserClient, attributes?: SplitIO.Attributes) {
131-
if (attributes) client.setAttributes(attributes);
130+
export function initAttributes(client: SplitIO.IBrowserClient | null, attributes?: SplitIO.Attributes) {
131+
if (client && attributes) client.setAttributes(attributes);
132132
}
133133

134134
const TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;

types/utils.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IFactoryWithClients extends SplitIO.IBrowserSDK {
1919
}
2020
export declare const __factories: Map<SplitIO.IBrowserSettings, IFactoryWithClients>;
2121
export declare function getSplitFactory(config: SplitIO.IBrowserSettings): IFactoryWithClients;
22-
export declare function getSplitSharedClient(factory: SplitIO.IBrowserSDK, key: SplitIO.SplitKey, trafficType?: string, _attributes?: SplitIO.Attributes): IClientWithContext;
22+
export declare function getSplitSharedClient(factory: SplitIO.IBrowserSDK, key: SplitIO.SplitKey, trafficType?: string): IClientWithContext;
2323
export declare function destroySplitFactory(factory: IFactoryWithClients): Promise<void[]>;
2424
export interface IClientStatus {
2525
isReady: boolean;
@@ -40,4 +40,4 @@ export declare function validateFeatureFlags(maybeFeatureFlags: unknown, listNam
4040
/**
4141
* Manage client attributes binding
4242
*/
43-
export declare function initAttributes(client: SplitIO.IBrowserClient, attributes?: SplitIO.Attributes): void;
43+
export declare function initAttributes(client: SplitIO.IBrowserClient | null, attributes?: SplitIO.Attributes): void;

0 commit comments

Comments
 (0)