From b91c6080591cb24602a389a3d839a16e9a3ca10e Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 19 Apr 2026 13:45:24 +0200 Subject: [PATCH 1/2] fix(node-sdk): preserve bound context on rebind --- packages/node-sdk/src/client.ts | 15 ++++++++++++--- packages/node-sdk/test/client.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/node-sdk/src/client.ts b/packages/node-sdk/src/client.ts index 89735ba2..1c1ab7fc 100644 --- a/packages/node-sdk/src/client.ts +++ b/packages/node-sdk/src/client.ts @@ -1832,9 +1832,18 @@ export class BoundReflagClient { // merge new context into existing const boundConfig = { ...this._options, - user: user ? { ...this._options.user, ...user } : undefined, - company: company ? { ...this._options.company, ...company } : undefined, - other: { ...this._options.other, ...other }, + user: + user === undefined + ? this._options.user + : { ...this._options.user, ...user }, + company: + company === undefined + ? this._options.company + : { ...this._options.company, ...company }, + other: + other === undefined + ? this._options.other + : { ...this._options.other, ...other }, enableTracking: enableTracking ?? this._options.enableTracking, meta: meta ?? this._options.meta, }; diff --git a/packages/node-sdk/test/client.test.ts b/packages/node-sdk/test/client.test.ts index e2cf65cb..d7819c93 100644 --- a/packages/node-sdk/test/client.test.ts +++ b/packages/node-sdk/test/client.test.ts @@ -3035,6 +3035,31 @@ describe("BoundReflagClient", () => { }); }); + it("should preserve existing user and company when omitted on rebind", () => { + const reboundClient = client + .bindClient({ user, company }) + .bindClient({ other: otherContext }); + + expect(reboundClient["_options"]).toEqual({ + user, + company, + other: otherContext, + enableTracking: true, + }); + }); + + it("should preserve existing other context when omitted on rebind", () => { + const reboundClient = client + .bindClient({ other: otherContext }) + .bindClient({ user }); + + expect(reboundClient["_options"]).toEqual({ + user, + other: otherContext, + enableTracking: true, + }); + }); + it("should allow using expected methods when bound to user", async () => { const boundClient = client.bindClient({ user }); expect(boundClient.user).toEqual(user); From d7798f8e6f2b8511958ed21ba4f8a6b7facae131 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 19 Apr 2026 13:59:16 +0200 Subject: [PATCH 2/2] chore(changeset): add node-sdk release note --- .changeset/node-sdk-bind-client-preserve-context.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/node-sdk-bind-client-preserve-context.md diff --git a/.changeset/node-sdk-bind-client-preserve-context.md b/.changeset/node-sdk-bind-client-preserve-context.md new file mode 100644 index 00000000..9d57ee13 --- /dev/null +++ b/.changeset/node-sdk-bind-client-preserve-context.md @@ -0,0 +1,5 @@ +--- +"@reflag/node-sdk": patch +--- + +Fix `BoundReflagClient.bindClient()` so omitted `user`, `company`, and `other` fields preserve the previously bound context instead of being cleared.