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
6 changes: 6 additions & 0 deletions .changeset/cyan-flowers-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/shared': patch
'@clerk/clerk-js': patch
---

Fix TelemetryCollector logic for clerk-js in browser to properly populate sdkMetadata for telemetry events.
6 changes: 1 addition & 5 deletions packages/shared/src/telemetry/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ interface WindowWithClerk extends Window {
*/
function isWindowClerkWithMetadata(clerk: unknown): clerk is { constructor: { sdkMetadata?: SDKMetadata } } {
return (
typeof clerk === 'object' &&
clerk !== null &&
'constructor' in clerk &&
typeof clerk.constructor === 'object' &&
clerk.constructor !== null
typeof clerk === 'object' && clerk !== null && 'constructor' in clerk && typeof clerk.constructor === 'function'
);
}
Comment on lines 41 to 45
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding tests for the type guard function.

While the fix is correct, adding unit tests would help prevent future regressions and ensure the type guard works as expected in various scenarios.

Consider adding tests that cover:

  • Valid clerk instances with constructor functions
  • Edge cases where constructor might be undefined or different types
  • Verification that sdkMetadata is properly populated after the fix
// Example test cases
describe('isWindowClerkWithMetadata', () => {
  it('should return true for valid clerk with function constructor', () => {
    const clerk = { constructor: function() {} };
    expect(isWindowClerkWithMetadata(clerk)).toBe(true);
  });
  
  it('should return false when constructor is not a function', () => {
    const clerk = { constructor: {} };
    expect(isWindowClerkWithMetadata(clerk)).toBe(false);
  });
});
🤖 Prompt for AI Agents
In packages/shared/src/telemetry/collector.ts around lines 41 to 45, add unit
tests for the isWindowClerkWithMetadata type guard function. Create tests that
verify it returns true for valid clerk objects with function constructors, false
when constructor is not a function or missing, and check cases where sdkMetadata
is present or absent. This will ensure the type guard behaves correctly across
different scenarios and prevent regressions.


Expand Down