-
Notifications
You must be signed in to change notification settings - Fork 409
fix(clerk-js): Mark SignIn/SignUpFuture resource properties as private #7321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 2b6d58c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR fixes a JSON serialization issue in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (2)
19-23: Consider enhancing the serialization test.The test successfully verifies that JSON.stringify doesn't throw an error (which would occur with circular references). However, it could be more robust by also validating that the serialized output contains expected properties.
Optional enhancement:
it('can be serialized with JSON.stringify', () => { const signIn = new SignIn(); const snapshot = JSON.stringify(signIn); expect(snapshot).toBeDefined(); + const parsed = JSON.parse(snapshot); + expect(parsed).toBeTypeOf('object'); });
80-84: Consider enhancing the SignInFuture serialization test.Similar to the SignIn test, this could be enhanced to validate the JSON structure.
Optional enhancement:
it('can be serialized with JSON.stringify', () => { const signIn = new SignIn(); const snapshot = JSON.stringify(signIn.__internal_future); expect(snapshot).toBeDefined(); + const parsed = JSON.parse(snapshot); + expect(parsed).toBeTypeOf('object'); });packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts (1)
29-40: LGTM! Serialization tests provide good coverage.The tests verify that both SignUp and SignUpFuture can be serialized without circular reference errors. The test structure is consistent with the SignIn tests.
Optional enhancement (similar to SignIn tests):
it('can be serialized with JSON.stringify', () => { const signUp = new SignUp(); const snapshot = JSON.stringify(signUp); expect(snapshot).toBeDefined(); + const parsed = JSON.parse(snapshot); + expect(parsed).toBeTypeOf('object'); });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
.changeset/dark-sides-beg.md(1 hunks)packages/clerk-js/src/core/resources/SignIn.ts(32 hunks)packages/clerk-js/src/core/resources/SignUp.ts(13 hunks)packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts(2 hunks)packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Prefer importing types from
@clerk/shared/typesinstead of the deprecated@clerk/typesalias
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use real Clerk instances for integration tests
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
packages/clerk-js/src/core/resources/__tests__/SignUp.test.tspackages/clerk-js/src/core/resources/__tests__/SignIn.test.tspackages/clerk-js/src/core/resources/SignIn.tspackages/clerk-js/src/core/resources/SignUp.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignUp.test.ts (1)
packages/clerk-js/src/core/resources/SignUp.ts (1)
SignUp(82-573)
packages/clerk-js/src/core/resources/SignUp.ts (1)
packages/clerk-js/src/utils/runAsyncResourceTask.ts (1)
runAsyncResourceTask(10-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
.changeset/dark-sides-beg.md (1)
1-5: LGTM! Changeset accurately documents the serialization fix.The changeset correctly describes the fix for the circular reference issue that prevented JSON.stringify from working with SignIn and SignUp instances.
packages/clerk-js/src/core/resources/SignUp.ts (3)
583-587: LGTM! Private field correctly prevents circular reference in serialization.The conversion from a public
readonly resourceproperty to a private#resourcefield is the correct fix. The private field syntax ensures the resource is not enumerable, preventing JSON.stringify from encountering the circular reference between SignUp and SignUpFuture instances.
589-685: All getter methods correctly updated to use private field.All getter methods have been consistently updated to reference
this.#resourceinstead ofthis.resource. The logic remains unchanged, maintaining functional equivalence while fixing the serialization issue.
687-956: All methods correctly refactored to use private resource field.All async methods and the new private
getCaptchaTokenhelper have been consistently updated to referencethis.#resource. The refactoring maintains functional equivalence while ensuring the resource reference doesn't create circular dependencies during serialization.packages/clerk-js/src/core/resources/SignIn.ts (4)
634-638: LGTM! Private field correctly prevents circular reference in SignIn serialization.Identical to SignUpFuture, the conversion to a private
#resourcefield ensures the resource reference is not enumerable, preventing circular reference errors during JSON.stringify.
640-691: All SignInFuture getter methods correctly updated.All getter methods consistently reference
this.#resource, maintaining the same logic while fixing the serialization issue. The nested property accesses inisTransferableandexistingSessionare handled correctly.
693-1175: All SignInFuture methods correctly refactored to use private field.All async methods have been comprehensively updated to reference
this.#resourcefor property access, method calls, and when passing the resource torunAsyncResourceTask. The refactoring is thorough and maintains functional behavior.
1177-1231: selectFirstFactor helper method correctly updated.The private
selectFirstFactorhelper method has been properly updated to referencethis.#resource.supportedFirstFactorsandthis.#resource.identifier, maintaining its logic while using the private field.
wobsoriano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒
Description
This PR fixes an issue where
SignInandSignUpinstances were unable to be serialized withJSON.stringifydue to a circular reference between themselves and theirFutureclasses. The issue was resolved by markingresourceas a private field, which excludes it from serialization.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.