-
Couldn't load subscription status.
- Fork 402
feat(clerk-js,clerk-react,types): Signal SignUp #6568
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
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,7 @@ | ||
| --- | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/clerk-react': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| [Experimental] Signal implementation for SignUp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import type { SignInSignal, SignUpSignal } from '@clerk/types'; | ||
| import { useCallback, useSyncExternalStore } from 'react'; | ||
|
|
||
| import { useIsomorphicClerkContext } from '../contexts/IsomorphicClerkContext'; | ||
| import { useAssertWrappedByClerkProvider } from './useAssertWrappedByClerkProvider'; | ||
|
|
||
| function useClerkSignal(signal: 'signIn') { | ||
| useAssertWrappedByClerkProvider('useSignInSignal'); | ||
| function useClerkSignal(signal: 'signIn'): ReturnType<SignInSignal> | null; | ||
| function useClerkSignal(signal: 'signUp'): ReturnType<SignUpSignal> | null; | ||
| function useClerkSignal(signal: 'signIn' | 'signUp'): ReturnType<SignInSignal> | ReturnType<SignUpSignal> | null { | ||
| useAssertWrappedByClerkProvider('useClerkSignal'); | ||
|
Comment on lines
+7
to
+10
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 chainEnsure hook is re-exported from the package entrypoint and add basic tests Please confirm useSignUpSignal is exported from the public React package entry and add at least smoke tests covering initial null, update on state change, and error propagation. Run the following to verify exports and test coverage placeholders: Also applies to: 58-64 🏁 Script executed: #!/bin/bash
# Check if useSignUpSignal is exported from the React package entrypoint(s)
fd -t f index.ts packages/react | xargs -I{} rg -nP -C2 "useSignUpSignal" {}
# Check for existing tests referencing the hook
rg -nP -C2 --type=ts "useSignUpSignal" packages/react
# If not present, I can scaffold react-testing-library tests analogous to existing SignIn hook tests.Length of output: 440 Export hooks from the public React entrypoint and add smoke tests The
You can mirror the existing Sign-In hook tests to keep consistency. 🤖 Prompt for AI Agents |
||
|
|
||
| const clerk = useIsomorphicClerkContext(); | ||
|
|
||
|
|
@@ -20,6 +23,10 @@ function useClerkSignal(signal: 'signIn') { | |
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know that the state is defined | ||
| clerk.__internal_state!.signInSignal(); | ||
| break; | ||
| case 'signUp': | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know that the state is defined | ||
| clerk.__internal_state!.signUpSignal(); | ||
| break; | ||
| default: | ||
| throw new Error(`Unknown signal: ${signal}`); | ||
| } | ||
|
|
@@ -36,6 +43,8 @@ function useClerkSignal(signal: 'signIn') { | |
| switch (signal) { | ||
| case 'signIn': | ||
| return clerk.__internal_state.signInSignal(); | ||
| case 'signUp': | ||
| return clerk.__internal_state.signUpSignal(); | ||
| default: | ||
| throw new Error(`Unknown signal: ${signal}`); | ||
| } | ||
|
|
@@ -49,3 +58,7 @@ function useClerkSignal(signal: 'signIn') { | |
| export function useSignInSignal() { | ||
| return useClerkSignal('signIn'); | ||
| } | ||
|
|
||
| export function useSignUpSignal() { | ||
| return useClerkSignal('signUp'); | ||
| } | ||
|
Comment on lines
+61
to
+64
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. 🛠️ Refactor suggestion Expose explicit return type and mark as experimental; consider similar treatment for useSignInSignal Public hooks should have explicit return types. Also surface the experimental nature of the new hook in JSDoc. Apply this diff: -export function useSignUpSignal() {
- return useClerkSignal('signUp');
-}
+/**
+ * @experimental A React hook that subscribes to the SignUp Signal.
+ * Returns a snapshot with `{ errors, fetchStatus, signUp }`, or `null` before Clerk state is ready.
+ */
+export function useSignUpSignal(): ReturnType<State['signUpSignal']> | null {
+ return useClerkSignal('signUp');
+}Additionally, for consistency, annotate /**
* A React hook that subscribes to the SignIn Signal.
* Returns a snapshot with `{ errors, fetchStatus, signIn }`, or `null` before Clerk state is ready.
*/
export function useSignInSignal(): ReturnType<State['signInSignal']> | null {
return useClerkSignal('signIn');
}And ensure the type-only import: import type { State } from '@clerk/types';Lastly, please add or update tests to cover:
Happy to scaffold react-testing-library tests that simulate state updates via the internal state adapter. 🤖 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
Add tests to cover SignUp signal behavior (parity with SignIn tests)
No tests are shown in this PR. Please add tests for:
I can scaffold these tests. Meanwhile, to check current coverage, run:
🏁 Script executed:
Length of output: 5847
Add unit tests for SignUp signal behavior
To achieve parity with existing SignIn tests, please add tests covering the following scenarios for
signUpComputedSignalinpackages/clerk-js(e.g. under a new__tests__folder alongsidesignals.ts):'idle'→'fetching'→'idle'when a sign-up request starts and finishes.errorsToParsedErrors(error)for both field-specific and global errors.SignUpresource arrives you getsignUp: null, then once it’s set you get the correct__internal_futurevalue.🤖 Prompt for AI Agents