-
Notifications
You must be signed in to change notification settings - Fork 407
feat(clerk-js,clerk-react,shared): Operation-specific errors fields #7195
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: 8b52a19 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.
|
WalkthroughIntroduces flow-specific error types and parsing: a generic Changes
Sequence Diagram(s)sequenceDiagram
participant API as API
participant Parser as errorsToParsedErrors<T>
participant Wrapper as errorsToSignIn/SignUpErrors
participant Signal as signIn/signUp Signal
participant Proxy as StateProxy
API->>Wrapper: returns error payload
Wrapper->>Parser: call with (error, initialFields)
Parser-->>Wrapper: Errors<T> { fields, raw, global }
Wrapper-->>Signal: mapped SignInErrors/SignUpErrors
Signal-->>Proxy: updated signal value (errors property)
Note right of Parser `#D6EAF8`: Parser guards against unknown fields\nand preserves initial shape
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/shared/src/types/state.ts (1)
63-100: Don't drop sign-up field errors forweb3Wallet/unsafeMetadata.
errorsToParsedErrorsonly assigns parsed field errors when the key already exists onfields. BecauseSignUpFieldsomitsweb3WalletandunsafeMetadata—both exposed on the sign-up resource—any API validation error targetingweb3_walletorunsafe_metadatanow gets silently discarded. That breaks downstream UIs that rely on those errors (e.g., custom metadata validation). Please add these fields here, and mirror them in the default/error factories so the parser can surface those errors again.Apply this diff (and keep the same additions in the other call sites):
export interface SignUpFields { @@ captcha: FieldError | null; /** * The error for the legal accepted field. */ legalAccepted: FieldError | null; + /** + * The error for the web3 wallet field. + */ + web3Wallet: FieldError | null; + /** + * The error for the unsafe metadata field. + */ + unsafeMetadata: FieldError | null; }packages/react/src/stateProxy.ts (1)
17-31: Keep default sign-up errors in sync with the type.After adding
web3WalletandunsafeMetadatatoSignUpFields, the default constructor should seed those slots so consumers never seeundefinedand parsed errors can land.Add the missing fields:
const defaultSignUpErrors = (): SignUpErrors => ({ fields: { firstName: null, lastName: null, emailAddress: null, phoneNumber: null, password: null, username: null, code: null, captcha: null, legalAccepted: null, + web3Wallet: null, + unsafeMetadata: null, }, raw: null, global: null, });
📜 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/clear-flowers-guess.md(1 hunks)packages/clerk-js/src/core/signals.ts(6 hunks)packages/react/src/stateProxy.ts(3 hunks)packages/shared/src/types/state.ts(4 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/clear-flowers-guess.md
**/*.{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/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.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/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.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/react/src/stateProxy.tspackages/shared/src/types/state.tspackages/clerk-js/src/core/signals.ts
🧬 Code graph analysis (3)
packages/react/src/stateProxy.ts (1)
packages/shared/src/types/state.ts (2)
SignInErrors(105-105)SignUpErrors(110-110)
packages/shared/src/types/state.ts (1)
packages/shared/src/errors/globalHookError.ts (1)
ClerkGlobalHookError(23-23)
packages/clerk-js/src/core/signals.ts (1)
packages/shared/src/types/state.ts (3)
Errors(26-40)SignInErrors(105-105)SignUpErrors(110-110)
⏰ 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). (4)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/clear-flowers-guess.md (1)
1-7: Changelog entry looks good.Release note and version bumps match the scoped change.
| function errorsToSignUpErrors(error: ClerkError | null): SignUpErrors { | ||
| return errorsToParsedErrors(error, { | ||
| firstName: null, | ||
| lastName: null, | ||
| emailAddress: null, | ||
| phoneNumber: null, | ||
| password: null, | ||
| username: null, | ||
| code: null, | ||
| captcha: null, | ||
| legalAccepted: null, | ||
| }); |
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.
Initialize all sign-up fields before parsing errors.
Once we add web3Wallet and unsafeMetadata to SignUpFields, we also need to seed them here. Otherwise the name in parsedErrors.fields guard still filters those errors out at runtime.
Please extend the initializer accordingly:
function errorsToSignUpErrors(error: ClerkError | null): SignUpErrors {
return errorsToParsedErrors(error, {
firstName: null,
lastName: null,
emailAddress: null,
phoneNumber: null,
password: null,
username: null,
code: null,
captcha: null,
legalAccepted: null,
+ web3Wallet: null,
+ unsafeMetadata: null,
});
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function errorsToSignUpErrors(error: ClerkError | null): SignUpErrors { | |
| return errorsToParsedErrors(error, { | |
| firstName: null, | |
| lastName: null, | |
| emailAddress: null, | |
| phoneNumber: null, | |
| password: null, | |
| username: null, | |
| code: null, | |
| captcha: null, | |
| legalAccepted: null, | |
| }); | |
| function errorsToSignUpErrors(error: ClerkError | null): SignUpErrors { | |
| return errorsToParsedErrors(error, { | |
| firstName: null, | |
| lastName: null, | |
| emailAddress: null, | |
| phoneNumber: null, | |
| password: null, | |
| username: null, | |
| code: null, | |
| captcha: null, | |
| legalAccepted: null, | |
| web3Wallet: null, | |
| unsafeMetadata: null, | |
| }); | |
| } |
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/signals.ts around lines 97 to 108, the initializer
object passed to errorsToParsedErrors is missing the new SignUpFields keys
web3Wallet and unsafeMetadata, so those errors get filtered out at runtime;
update the initializer to include web3Wallet: null and unsafeMetadata: null
alongside the existing fields so all sign-up fields are seeded before parsing.
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
♻️ Duplicate comments (1)
packages/clerk-js/src/core/signals.ts (1)
97-109: Initialize all sign-up fields before parsing errors.Once we add
web3WalletandunsafeMetadatatoSignUpFields, we also need to seed them here. Otherwise thename in parsedErrors.fieldsguard still filters those errors out at runtime.Please extend the initializer accordingly:
function errorsToSignUpErrors(error: ClerkError | null): SignUpErrors { return errorsToParsedErrors(error, { firstName: null, lastName: null, emailAddress: null, phoneNumber: null, password: null, username: null, code: null, captcha: null, legalAccepted: null, + web3Wallet: null, + unsafeMetadata: null, }); }Based on past review comments.
📜 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/__tests__/signals.test.ts(1 hunks)packages/clerk-js/src/core/signals.ts(6 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/clerk-js/src/core/tests/signals.test.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/signals.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/signals.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/signals.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/signals.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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/signals.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/signals.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/signals.ts (1)
packages/shared/src/types/state.ts (3)
Errors(26-40)SignInErrors(105-105)SignUpErrors(110-110)
⏰ 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: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/clerk-js/src/core/signals.ts (4)
2-2: LGTM!The import statement correctly includes the new flow-specific error types
SignInErrorsandSignUpErrors.
13-21: LGTM!The sign-in computed signal correctly uses the new
errorsToSignInErrorshelper, properly integrating flow-specific error handling.
27-35: LGTM!The sign-up computed signal correctly uses the new
errorsToSignUpErrorshelper, properly integrating flow-specific error handling.
89-95: No issues found.All fields from the
SignInFieldsinterface are properly initialized. TheerrorsToSignInErrorsfunction correctly initializes all three fields—identifier,password, andcode—withnullvalues, matching the interface definition.
| if (name in parsedErrors.fields) { | ||
| (parsedErrors.fields as any)[name] = error; | ||
| } |
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.
Replace any with a type-safe assignment.
The use of any type casting violates the project's TypeScript guidelines, which require avoiding any types. While the guard at line 71 ensures the field exists, the type system isn't aware of this refinement.
Consider this type-safe alternative:
const name = snakeToCamel(error.meta.paramName);
if (name in parsedErrors.fields) {
- (parsedErrors.fields as any)[name] = error;
+ parsedErrors.fields = {
+ ...parsedErrors.fields,
+ [name]: error,
+ } as T;
}Or use a more explicit approach with a helper function that preserves type safety:
function setField<T extends Record<string, unknown>>(fields: T, key: string, value: unknown): T {
if (key in fields) {
return { ...fields, [key]: value } as T;
}
return fields;
}🤖 Prompt for AI Agents
In packages/clerk-js/src/core/signals.ts around lines 71 to 73, the code uses an
unsafe (parsedErrors.fields as any)[name] assignment; replace this with a
type-safe update so we avoid any casts. Use a typed index signature or a small
generic helper: narrow parsedErrors.fields to the appropriate Record<string,
unknown> (or the exact field type) before assigning, or call a helper like
setField<T extends Record<string, unknown>>(fields, key, value) that returns a
new fields object with the updated key typed as T; ensure the helper or
narrowing preserves the original fields type and returns the updated object back
into parsedErrors.fields without using any.
Description
This PR updates the
fieldstype onErrorsto be specific to either sign-in or sign-up. It also adds a basic test for theerrorsToParsedErrorsfunction.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit