-
Notifications
You must be signed in to change notification settings - Fork 405
fix(clerk-js): Prepare calls would fire only once #6695
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
Changes from all commits
664822a
cbca675
e9bdff4
4a97f33
487158c
51340a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
|
|
||
| Fixes issue where "prepare" API request would only fire once, preventing end users from receiving fresh otp codes. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,17 +36,15 @@ export const SignUpPhoneCodeCard = withCardStateProvider(() => { | |
| // because the verification is already created on the Start screen | ||
| shouldAvoidPrepare || isAlternativePhoneCodeProvider | ||
| ? undefined | ||
| : () => | ||
| signUp | ||
| .preparePhoneNumberVerification({ strategy: 'phone_code', channel: undefined }) | ||
| .catch(err => handleError(err, [], card.setError)), | ||
| : () => signUp.preparePhoneNumberVerification({ strategy: 'phone_code', channel: undefined }), | ||
| { | ||
| name: 'signUp.preparePhoneNumberVerification', | ||
| strategy: 'phone_code', | ||
| number: signUp.phoneNumber, | ||
| }, | ||
| { | ||
| staleTime: 100, | ||
| onError: err => handleError(err, [], card.setError), | ||
| }, | ||
|
Comment on lines
46
to
48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify onError behavior with handleError rethrows; confirm staleTime=100ms is intentional
Run: Expected:
🏁 Script executed: #!/bin/bash
# Inspect onError invocation and error propagation in useFetch
rg -nP -C3 'function\s+useFetch|\bonError\b|\bcatch\s*\(' packages/clerk-js/src/ui/hooks/useFetch.ts
# Scan all useFetch callers for very short staleTime and generic names that could collide
rg -nP -C1 'useFetch\(' packages | sed -n '1,200p'Length of output: 5044 🏁 Script executed: #!/bin/bash
# Search for handleError definition and usage across clerk-js
rg -nR 'handleError' -n packages/clerk-jsLength of output: 446 🏁 Script executed: #!/bin/bash
# Show useFetch implementation including error invocation context
rg -nP -C10 'function\s+useFetch' packages/clerk-js/src/ui/hooks/useFetch.ts
rg -nP -C10 '\.catch' packages/clerk-js/src/ui/hooks/useFetch.ts
# Show import and usage of handleError in SignUpPhoneCodeCard
sed -n '1,50p' packages/clerk-js/src/ui/components/SignUp/SignUpPhoneCodeCard.tsx
# Search for handleError definition across the repo
rg -n 'handleError' -n .Length of output: 25854 🏁 Script executed: #!/bin/bash
# Inspect staleTime handling in useFetch
rg -nP -C5 'staleTime' packages/clerk-js/src/ui/hooks/useFetch.tsLength of output: 1310 🏁 Script executed: #!/bin/bash
rg -nP -C10 'export const handleError' packages/clerk-js/src/ui/utils/errorHandler.tsLength of output: 644 Guard
🤖 Prompt for AI Agents |
||
| ); | ||
|
|
||
|
|
||
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.
💡 Verification agent
🧩 Analysis chain
Verify onError safety with handleError rethrows; double-check staleTime
Same concern as the phone code card: confirm
useFetchwon’t surface unhandled exceptions ifhandleErrorrethrows, and thatstaleTime: 100meets the intended dedupe window.Run:
Expected:
onErrorinvocation cannot crash the component tree.🏁 Script executed:
Length of output: 285
🏁 Script executed:
Length of output: 5357
🏁 Script executed:
Length of output: 5735
🏁 Script executed:
Length of output: 209
Ensure onError callback safety and clarify staleTime usage
useFetch(packages/clerk-js/src/ui/hooks/useFetch.ts), wrap theoptions.onError?.(e)invocation in atry/catchto prevent unhandled promise rejections ifhandleErrorthrows.staleTime(in SignUpEmailCodeCard.tsx and SignUpPhoneCodeCard.tsx) provides the intended dedupe window for “prepare fires once” semantics.🤖 Prompt for AI Agents