-
Notifications
You must be signed in to change notification settings - Fork 391
fix(clerk-js): Add private _create method for use inside runAsyncResourceTask #6932
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: 5031aa1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 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.
|
WalkthroughAdds private _create helpers to SignInFuture and SignUpFuture; SignUpFuture.create now wraps _create with runAsyncResourceTask. Expands SignUpFutureCreateParams with emailAddress, phoneNumber, username and renames SignIn password param Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant UI
participant SignInFuture
participant _create_SignIn as "_create (SignIn)"
participant Resource as "Resource.__internal_basePost"
User->>UI: Trigger sign-in create
UI->>SignInFuture: create(params)
SignInFuture->>_create_SignIn: params
_create_SignIn->>Resource: basePost(pathRoot, params)
alt Success
Resource-->>_create_SignIn: result
_create_SignIn-->>SignInFuture: result
SignInFuture-->>UI: result
else Error
Resource-->>_create_SignIn: error
_create_SignIn-->>SignInFuture: error
SignInFuture-->>UI: error propagated
end
sequenceDiagram
actor User
participant UI
participant SignUpFuture
participant runAsyncTask as "runAsyncResourceTask"
participant _create_SignUp as "_create (SignUp)"
participant Resource as "Resource.__internal_basePost"
User->>UI: Trigger sign-up create
UI->>SignUpFuture: create(params)
SignUpFuture->>runAsyncTask: wrap async task
runAsyncTask->>_create_SignUp: params
Note right of _create_SignUp: Normalize unsafeMetadata\nAttach captcha data\nBuild request body
_create_SignUp->>Resource: basePost(pathRoot, body)
alt Success
Resource-->>_create_SignUp: result
_create_SignUp-->>runAsyncTask: result
runAsyncTask-->>SignUpFuture: result
SignUpFuture-->>UI: result
else Error
Resource-->>_create_SignUp: error
_create_SignUp-->>runAsyncTask: error
runAsyncTask-->>SignUpFuture: error
SignUpFuture-->>UI: error propagated
end
Note over SignUpFuture,_create_SignUp: Internal web3/auth flows now call _create directly
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
📜 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 (4)
.changeset/purple-toys-refuse.md
(1 hunks)packages/clerk-js/src/core/resources/SignIn.ts
(2 hunks)packages/clerk-js/src/core/resources/SignUp.ts
(2 hunks)packages/types/src/signUpFuture.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
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
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/types/src/signUpFuture.ts
packages/clerk-js/src/core/resources/SignIn.ts
packages/clerk-js/src/core/resources/SignUp.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/purple-toys-refuse.md
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/types/src/signInFuture.ts (1)
SignInFutureCreateParams
(7-14)packages/clerk-js/src/utils/runAsyncResourceTask.ts (1)
runAsyncResourceTask
(8-31)
packages/clerk-js/src/core/resources/SignUp.ts (2)
packages/types/src/signUpFuture.ts (1)
SignUpFutureCreateParams
(13-20)packages/clerk-js/src/utils/runAsyncResourceTask.ts (1)
runAsyncResourceTask
(8-31)
⏰ 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). (6)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (7)
packages/types/src/signUpFuture.ts (1)
14-16
: LGTM! Type expansion maintains backward compatibility.The addition of
emailAddress
,phoneNumber
, andusername
as optional fields appropriately expands the input surface for sign-up creation while maintaining backward compatibility. These fields align with the updated_create
implementation in SignUp.ts.packages/clerk-js/src/core/resources/SignIn.ts (3)
706-711
: LGTM! Private helper correctly extracts core logic.The new private
_create
method appropriately extracts the core sign-in creation logic withoutrunAsyncResourceTask
, enabling internal callers to avoid problematic nesting while maintaining the same error propagation behavior.
713-717
: LGTM! Public API correctly wraps private implementation.The public
create
method appropriately wraps_create
withrunAsyncResourceTask
, maintaining the existing API contract while delegating to the new private helper. This ensures proper error propagation and event emission for external callers.
751-751
: LGTM! Internal caller correctly uses private helper.The
sendEmailCode
method now correctly calls_create
instead ofcreate
, preventing nestedrunAsyncResourceTask
calls since this method already wraps its logic withrunAsyncResourceTask
at line 749.packages/clerk-js/src/core/resources/SignUp.ts (3)
663-676
: LGTM! Private helper correctly encapsulates creation logic.The new private
_create
method appropriately encapsulates the sign-up creation logic, including captcha token retrieval, request body construction, andunsafeMetadata
normalization. This enables internal callers to avoid nestedrunAsyncResourceTask
calls while maintaining consistent behavior.
678-681
: LGTM! Public API maintains contract with proper wrapping.The public
create
method correctly wraps_create
withrunAsyncResourceTask
, preserving the existing API contract and ensuring proper error propagation and event emission for external callers.
815-815
: LGTM! Internal caller correctly avoids nested task wrapping.The
web3
method now correctly calls_create
instead ofcreate
, preventing nestedrunAsyncResourceTask
calls since this entire method is already wrapped withrunAsyncResourceTask
at line 789.
@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 (2)
packages/clerk-js/src/core/resources/SignUp.ts (2)
663-676
: Add JSDoc and explicit return type for the private helper.The private
_create
method is a key part of fixing the nestedrunAsyncResourceTask
issue, but lacks documentation explaining its purpose and when to use it vs the publiccreate
method.Apply this diff to add documentation and an explicit return type:
+ /** + * Internal helper for creating a sign-up without wrapping in runAsyncResourceTask. + * Use this method when calling from within another method that's already wrapped + * in runAsyncResourceTask to prevent nesting issues. + * @private + */ - private async _create(params: SignUpFutureCreateParams): Promise<void> { + private async _create(params: SignUpFutureCreateParams): Promise<void> {
764-769
: Consider more specific error handling for URL parsing.The empty catch block catches all errors, not just URL parsing errors. This could potentially hide other unexpected errors.
Apply this diff to be more explicit:
let redirectUrlComplete = redirectUrl; try { new URL(redirectUrl); + redirectUrlComplete = redirectUrl; } catch { - redirectUrlComplete = window.location.origin + redirectUrl; + // If URL parsing fails, redirectUrl is relative - make it absolute + redirectUrlComplete = window.location.origin + redirectUrl; }Alternatively, for better clarity and to only catch URL constructor errors:
- let redirectUrlComplete = redirectUrl; - try { - new URL(redirectUrl); - } catch { - redirectUrlComplete = window.location.origin + redirectUrl; - } + // If redirectUrl is relative, make it absolute + let redirectUrlComplete: string; + try { + new URL(redirectUrl); + redirectUrlComplete = redirectUrl; + } catch (err) { + if (err instanceof TypeError) { + redirectUrlComplete = window.location.origin + redirectUrl; + } else { + throw err; + } + }
📜 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 (2)
packages/clerk-js/src/core/resources/SignIn.ts
(6 hunks)packages/clerk-js/src/core/resources/SignUp.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
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
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/core/resources/SignUp.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/core/resources/SignUp.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/SignUp.ts (2)
packages/types/src/signUpFuture.ts (1)
SignUpFutureCreateParams
(13-20)packages/clerk-js/src/utils/runAsyncResourceTask.ts (1)
runAsyncResourceTask
(8-31)
⏰ 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: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/clerk-js/src/core/resources/SignUp.ts (3)
678-682
: LGTM!The refactor correctly delegates to
_create
while preserving therunAsyncResourceTask
wrapper for the public API. This prevents the nested task issue when internal methods need to call creation logic.
776-776
: LGTM!Using
redirectUrlComplete
ensures that absolute URLs are always sent to the API, which is the correct behavior after the URL normalization logic.
823-823
: LGTM!Correctly uses
_create
instead ofcreate
to avoid nestedrunAsyncResourceTask
calls. This ensures errors propagate properly to Signals, which is the primary fix described in the PR objectives.
Description
This PR fixes an issue where errors thrown from
this.create
weren't correctly propagated to Signals since we were nesting calls torunAsyncResourceTask
. This is fixed by adding a private_create
method that other methods can call which does not userunAsyncResourceTask
.It also fixes an issue where
email
was used instead ofemailAddress
forsignIn.password()
.It also fixes an issue where the
redirectUrl
parameter used in the SSO flow was not made absolute before calling the FAPI endpoint.Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit