Skip to content

Conversation

@mattmikolay
Copy link
Contributor

@mattmikolay mattmikolay commented Aug 6, 2025

Description

This PR updates our client SDK and React SDK to support specifying a branch option in the Knock client, the <KnockProvider> component, and the useAuthenticatedKnockClient hook.

I’m marking this PR with the “do not merge” label until we’re ready to ship this.

Checklist

  • Tests have been added for new features or major refactors to existing features.

@linear
Copy link

linear bot commented Aug 6, 2025

@changeset-bot
Copy link

changeset-bot bot commented Aug 6, 2025

🦋 Changeset detected

Latest commit: 3173ae7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@knocklabs/react-core Patch
nextjs-example Patch
@knocklabs/client Patch
@knocklabs/expo Patch
@knocklabs/react-native Patch
@knocklabs/react Patch
client-example Patch
guide-example Patch
@knocklabs/expo-example Patch
ms-teams-connect-example Patch
nextjs-app-dir-example Patch
slack-connect-example Patch
slack-kit-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor Author

mattmikolay commented Aug 6, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@mattmikolay mattmikolay changed the title feat(KNO-9338): add branch option to ApiClient and Knock feat(KNO-9338): add branch configuration option Aug 6, 2025
@mattmikolay mattmikolay changed the title feat(KNO-9338): add branch configuration option feat(KNO-9338): add branch configuration options Aug 6, 2025
@vercel
Copy link

vercel bot commented Aug 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
javascript-ms-teams-connect-example Ready Ready Preview Comment Nov 7, 2025 10:24pm
javascript-nextjs-example Ready Ready Preview Comment Nov 7, 2025 10:24pm
javascript-slack-connect-example Ready Ready Preview Comment Nov 7, 2025 10:24pm
javascript-slack-kit-example Ready Ready Preview Comment Nov 7, 2025 10:24pm

Copy link
Member

@kylemcd kylemcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so good! Appreciate all the docs and the tests 🙏

Comment on lines +17 to +19
{ id: user.id },
undefined, // userToken when needed
{ branch: "my-branch-slug" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, really wish we would have just put these 3 into a single object when creating this hook originally :(

cursor[bot]

This comment was marked as outdated.

) {
this.host = options.host || DEFAULT_HOST;
this.logLevel = options.logLevel;
this.branch = options.branch || undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Null Branch Value Causes Header and Parameter Errors

The ApiClient class initializes this.branch to null when the branch option is undefined. This null value is then incorrectly used for the X-Knock-Branch HTTP header and the branch_slug WebSocket parameter, which should be strings or omitted.

Additional Locations (2)
Fix in Cursor Fix in Web

@mattmikolay mattmikolay force-pushed the mattmik-kno-9338-javascript-sdks-add-support-for-x-knock-branch-header-to-js branch from 6adce9f to 3173ae7 Compare November 7, 2025 22:22
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Knock instance reuses outdated configuration.

When userId or userToken changes simultaneously with branch (or host/logLevel), the hook reuses the existing Knock instance instead of creating a new one. Since branch is readonly and set during construction, the old branch value persists. The condition should verify that configuration options haven't changed before taking the early return path.

packages/react-core/src/modules/core/hooks/useAuthenticatedKnockClient.ts#L67-L76

if (
currentKnock &&
currentKnock.isAuthenticated() &&
(currentKnock.userId !== userId || currentKnock.userToken !== userToken)
) {
authenticateWithOptions(
currentKnock,
stableUserIdOrObject,
userToken,
stableOptions,

Fix in Cursor Fix in Web


@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.49%. Comparing base (9368d1e) to head (3173ae7).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #696      +/-   ##
==========================================
- Coverage   65.53%   65.49%   -0.05%     
==========================================
  Files         189      189              
  Lines        7771     7793      +22     
  Branches      954      956       +2     
==========================================
+ Hits         5093     5104      +11     
- Misses       2651     2662      +11     
  Partials       27       27              
Files with missing lines Coverage Δ
packages/client/src/api.ts 100.00% <100.00%> (ø)
packages/client/src/knock.ts 100.00% <100.00%> (ø)
...ct-core/src/modules/core/context/KnockProvider.tsx 96.22% <100.00%> (+0.22%) ⬆️
.../modules/core/hooks/useAuthenticatedKnockClient.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

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.

3 participants