Skip to content

Conversation

@alexcarpenter
Copy link
Member

@alexcarpenter alexcarpenter commented Jan 15, 2026

Description

Allow reseting signUp resource to allow navigating back to the start of a signup attempt without triggering fetchStatus as fetching.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Added a reset action for sign-in and sign-up that clears validation/errors and restores forms to an initial empty state without showing background fetching indicators.
    • Exposed reset on client state proxies so UI code can invoke it directly.
  • Tests

    • Added tests verifying reset clears errors, returns success, restores empty state, and avoids emitting a fetching status.
  • Chores

    • Bumped package patch versions and added changeset entries.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 66fc05d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@clerk/clerk-js Patch
@clerk/shared Patch
@clerk/chrome-extension Patch
@clerk/expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch

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

@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jan 23, 2026 7:09pm

Request Review

@alexcarpenter alexcarpenter requested a review from dstaley January 15, 2026 20:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds reset() methods to SignUp and SignIn future resources that clear local error state, mark the future as discardable, invoke client.resetSignUp()/client.resetSignIn(), and return Promise<{ error: ClerkError | null }> without emitting a resource:fetch fetching state. Renames internal finalization flag from hasBeenFinalized to canBeDiscarded. Declares reset() and canBeDiscarded in shared types, exposes reset on React state proxies, adds corresponding client resetSignIn/resetSignUp methods, and adds tests and changeset entries.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a reset method to SignIn and SignUp resources across the clerk-js package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 15, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7606

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7606

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7606

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7606

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7606

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7606

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@7606

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7606

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7606

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7606

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7606

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7606

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7606

@clerk/react

npm i https://pkg.pr.new/@clerk/react@7606

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7606

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7606

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7606

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7606

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7606

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7606

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7606

commit: 66fc05d

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🤖 Fix all issues with AI agents
In `@packages/clerk-js/src/core/resources/SignIn.ts`:
- Around line 1251-1265: reset() currently swaps the global signals but leaves
any existing SignInFuture instances bound to the old SignIn (so callers keep
stale state); modify reset() to also rebind or invalidate those futures: after
creating freshSignIn and calling signInResourceSignal({ resource: freshSignIn
}), iterate or access the current SignInFuture(s) associated with the previous
resource (the one referenced by SignInFuture) and either (a) update their
internal resource reference to freshSignIn (rebind) or (b) set their internal
finalized/invalid flag (e.g., `#hasBeenFinalized` or an .invalidate() method) so
they no longer operate on the old SignIn; ensure the code updates or exposes the
new SignInFuture where callers expect it so no caller continues to operate on
stale state.
📜 Review details

Configuration used: Repository YAML (base), Organization UI (inherited)

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7225024 and 8fd50e2.

📒 Files selected for processing (5)
  • .changeset/add-signin-reset.md
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/react/src/stateProxy.ts
  • packages/shared/src/types/signInFuture.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react/src/stateProxy.ts
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.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/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/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/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details in classes
Use protected for inheritance hierarchies
Use public explicitly 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 like Omit, Partial, and Pick for 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
Use const assertions with as const for literal types
Use satisfies operator 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/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use Prettier for code formatting across all packages

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/*

⚙️ CodeRabbit configuration file

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.

Files:

  • packages/shared/src/types/signInFuture.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.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__/SignIn.test.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__/SignIn.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use React Testing Library for component testing

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/SignIn.ts (1)
packages/clerk-js/src/core/signals.ts (2)
  • signInErrorSignal (20-20)
  • signInResourceSignal (19-19)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (3)
packages/clerk-js/src/core/signals.ts (2)
  • signInResourceSignal (19-19)
  • signInErrorSignal (20-20)
packages/clerk-js/src/core/events.ts (1)
  • eventBus (32-32)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (98-593)
⏰ 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). (25)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines 1251 to 1265
/**
* Resets the current sign-in attempt by clearing all local state back to null.
* Unlike other methods, this does NOT emit resource:fetch with 'fetching' status,
* allowing for smooth UI transitions without loading states.
*/
reset(): Promise<{ error: ClerkError | null }> {
// Clear errors
signInErrorSignal({ error: null });

// Create a fresh null SignIn instance and update the signal directly
const freshSignIn = new SignIn(null);
signInResourceSignal({ resource: freshSignIn });

return Promise.resolve({ error: null });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset leaves existing SignInFuture instances stale

reset() only swaps global signals; the current SignInFuture still points to the old SignIn (and retains #hasBeenFinalized). Callers that keep the instance can keep operating on stale state right after reset, which conflicts with the “reset current sign-in attempt” contract. Consider rebinding the future to the fresh resource or explicitly returning/invalidating the old instance to avoid stale usage.

🤖 Prompt for AI Agents
In `@packages/clerk-js/src/core/resources/SignIn.ts` around lines 1251 - 1265,
reset() currently swaps the global signals but leaves any existing SignInFuture
instances bound to the old SignIn (so callers keep stale state); modify reset()
to also rebind or invalidate those futures: after creating freshSignIn and
calling signInResourceSignal({ resource: freshSignIn }), iterate or access the
current SignInFuture(s) associated with the previous resource (the one
referenced by SignInFuture) and either (a) update their internal resource
reference to freshSignIn (rebind) or (b) set their internal finalized/invalid
flag (e.g., `#hasBeenFinalized` or an .invalidate() method) so they no longer
operate on the old SignIn; ensure the code updates or exposes the new
SignInFuture where callers expect it so no caller continues to operate on stale
state.

@alexcarpenter alexcarpenter changed the title feat(clerk-js): Add reset method to SignUp resource feat(clerk-js): Add reset method to Sign[In|Up] resource Jan 16, 2026
Copy link
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@alexcarpenter
Copy link
Member Author

closing in favor of #7662

@dstaley dstaley reopened this Jan 23, 2026
@dstaley
Copy link
Member

dstaley commented Jan 23, 2026

#7662 targets this PR :)

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🤖 Fix all issues with AI agents
In `@packages/clerk-js/src/core/resources/Client.ts`:
- Around line 97-107: resetSignIn() and resetSignUp() currently only emit
'resource:error' so the resource signals
(signInResourceSignal/signUpResourceSignal) are not updated; after creating the
new instance and emitting the error event, also emit a 'resource:update' event
via eventBus.emit('resource:update', { resource: this.signIn as SignIn }) and
similarly for this.signUp (cast as needed) so State.onResourceUpdated runs and
the resource signals reflect the new reset instance.
♻️ Duplicate comments (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)

1250-1262: Stale SignInFuture instance concern remains

This concern was already raised in a previous review. After reset() completes, the current SignInFuture instance (the one reset() was called on) still holds a reference to the old SignIn via #resource. Callers retaining a reference to this SignInFuture would operate on stale state.

Comment on lines +97 to +107
resetSignIn(): void {
this.signIn = new SignIn(null);
// Cast needed because this.signIn is typed as SignInResource (interface), not SignIn (class extending BaseResource)
eventBus.emit('resource:error', { resource: this.signIn as SignIn, error: null });
}

resetSignUp(): void {
this.signUp = new SignUp(null);
// Cast needed because this.signUp is typed as SignUpResource (interface), not SignUp (class extending BaseResource)
eventBus.emit('resource:error', { resource: this.signUp as SignUp, error: null });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== Client.ts resetSignIn and resetSignUp implementation ==="
sed -n '97,107p' packages/clerk-js/src/core/resources/Client.ts

echo ""
echo "=== State onResourceError handler ==="
rg -n -A 15 'onResourceError.*\(' packages/clerk-js/src/core/state.ts | head -40

echo ""
echo "=== State onResourceUpdated handler ==="
rg -n -A 20 'onResourceUpdated.*\(' packages/clerk-js/src/core/state.ts | head -50

echo ""
echo "=== SignIn constructor and initialization ==="
rg -n -A 10 'constructor.*null' packages/clerk-js/src/core/resources/SignIn.ts | head -30

echo ""
echo "=== Check if SignIn/SignUp emit resource:update on construction ==="
rg -n 'resource:update' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 2887


🏁 Script executed:

#!/bin/bash
echo "=== SignIn fromJSON implementation ==="
rg -n -A 20 'fromJSON.*=' packages/clerk-js/src/core/resources/SignIn.ts | head -50

echo ""
echo "=== shouldIgnoreNullUpdate implementation ==="
rg -n -B 2 -A 10 'shouldIgnoreNullUpdate' packages/clerk-js/src/core/state.ts

echo ""
echo "=== Context of resource:update at line 573 in SignIn.ts ==="
sed -n '565,580p' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 2223


🏁 Script executed:

#!/bin/bash
echo "=== Full fromJSON method in SignIn.ts ==="
rg -n -B 5 'resource:update.*this' packages/clerk-js/src/core/resources/SignIn.ts | grep -A 50 'fromJSON'

echo ""
echo "=== Check fromJSON method signature and start ==="
rg -n 'fromJSON\s*=' packages/clerk-js/src/core/resources/SignIn.ts -A 25 | head -40

echo ""
echo "=== Check if there's a condition on emitting resource:update ==="
sed -n '550,580p' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 1532


🏁 Script executed:

#!/bin/bash
echo "=== Check BaseResource for __internal_future property ==="
rg -n '__internal_future' packages/clerk-js/src/core/resources/ -B 2 -A 2

echo ""
echo "=== Check if canBeDiscarded is set anywhere in SignIn/SignUp ==="
rg -n 'canBeDiscarded' packages/clerk-js/src/core/resources/

echo ""
echo "=== How does __internal_future get set initially in BaseResource ==="
rg -n '__internal_future' packages/clerk-js/src/core/resources/BaseResource.ts -B 3 -A 3

Repository: clerk/javascript

Length of output: 50482


🏁 Script executed:

#!/bin/bash
echo "=== Search for canBeDiscarded implementation ==="
rg -n 'canBeDiscarded' packages/clerk-js/src/core/resources/ -B 3 -A 3

echo ""
echo "=== Check reset method in SignUpFuture ==="
rg -n -A 25 'reset.*=' packages/clerk-js/src/core/resources/SignUpFuture.ts | head -60

Repository: clerk/javascript

Length of output: 4761


🏁 Script executed:

#!/bin/bash
echo "=== Check tests for resetSignIn/resetSignUp behavior ==="
rg -n -B 5 -A 15 'resetSignIn|resetSignUp' packages/clerk-js/src/core/resources/__tests__/Client.test.ts 2>/dev/null | head -80

echo ""
echo "=== Check if there's a test for signal update after reset ==="
rg -n 'signInResourceSignal.*reset' packages/clerk-js/src/core/ -B 5 -A 5

echo ""
echo "=== Check the full reset flow in SignInFuture/SignUpFuture ==="
rg -n -B 2 -A 8 'reset\(\)' packages/clerk-js/src/core/resources/SignInFuture.ts 2>/dev/null | head -30

echo ""
echo "=== Check what happens when you create SignIn with null ==="
sed -n '160,175p' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 872


🏁 Script executed:

#!/bin/bash
echo "=== Check if there are tests showing expected behavior after reset ==="
rg -n 'reset.*signal\|signal.*reset' packages/clerk-js/src/core/resources/__tests__/ -B 5 -A 10 | head -100

echo ""
echo "=== Look at full SignUpFuture reset implementation ==="
rg -n -B 5 -A 10 'async reset' packages/clerk-js/src/core/resources/SignUp.ts

echo ""
echo "=== Look at full SignInFuture reset implementation ==="
rg -n -B 5 -A 10 'async reset' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 242


🏁 Script executed:

#!/bin/bash
echo "=== Find Future class files ==="
fd -t f 'Future' packages/clerk-js/src/core/resources/

echo ""
echo "=== Search for reset method in SignUp.ts ==="
grep -n "reset" packages/clerk-js/src/core/resources/SignUp.ts | head -20

echo ""
echo "=== Get the reset method from SignUp.ts ==="
sed -n '980,1000p' packages/clerk-js/src/core/resources/SignUp.ts

echo ""
echo "=== Get the reset method from SignIn.ts ==="
sed -n '1250,1270p' packages/clerk-js/src/core/resources/SignIn.ts

Repository: clerk/javascript

Length of output: 1948


🏁 Script executed:

#!/bin/bash
echo "=== Verify the reset flow: when is canBeDiscarded set? ==="
echo "In SignUpFuture.reset():"
sed -n '984,991p' packages/clerk-js/src/core/resources/SignUp.ts

echo ""
echo "Then Client.resetSignUp() is called:"
sed -n '104,107p' packages/clerk-js/src/core/resources/Client.ts

echo ""
echo "=== Check if shouldIgnoreNullUpdate would allow the update if canBeDiscarded is true ==="
sed -n '115,119p' packages/clerk-js/src/core/state.ts

echo ""
echo "=== Simulate the flow: does emitting resource:update fix it? ==="
echo "After Future.reset() sets canBeDiscarded=true, then Client.resetSignUp() is called"
echo "If resource:update is emitted, State.onResourceUpdated will:"
echo "1. Call shouldIgnoreNullUpdate(previousResource, newResource)"
echo "2. previousResource.__internal_future.canBeDiscarded is NOW true (set by Future.reset())"
echo "3. So shouldIgnoreNullUpdate returns: !newResource?.id && previousResource && false"
echo "4. Which is: true && true && false = FALSE"
echo "5. So the signal WILL be updated"

Repository: clerk/javascript

Length of output: 1747


🏁 Script executed:

#!/bin/bash
echo "=== Search for Client reset tests ==="
find packages/clerk-js/src -name "*.test.ts" -exec grep -l "resetSignIn\|resetSignUp" {} \;

echo ""
echo "=== Check if any tests verify signInResourceSignal is updated after reset ==="
rg -n 'signInResourceSignal' packages/clerk-js/src/core/resources/__tests__/

Repository: clerk/javascript

Length of output: 966


Emit resource:update event to update resource signal after reset

resetSignIn()/resetSignUp() only emit resource:error, which updates the error signal but not the resource signal. The signInResourceSignal/signUpResourceSignal never reflects the new reset instance because State's onResourceUpdated handler is never called.

When resource:update is emitted after canBeDiscarded is set to true (by the Future.reset() call), the shouldIgnoreNullUpdate check will pass and the signal will be properly updated.

Proposed fix
  resetSignIn(): void {
    this.signIn = new SignIn(null);
-   // Cast needed because this.signIn is typed as SignInResource (interface), not SignIn (class extending BaseResource)
-   eventBus.emit('resource:error', { resource: this.signIn as SignIn, error: null });
+   eventBus.emit('resource:update', { resource: this.signIn as SignIn });
+   eventBus.emit('resource:error', { resource: this.signIn as SignIn, error: null });
  }

  resetSignUp(): void {
    this.signUp = new SignUp(null);
-   // Cast needed because this.signUp is typed as SignUpResource (interface), not SignUp (class extending BaseResource)
-   eventBus.emit('resource:error', { resource: this.signUp as SignUp, error: null });
+   eventBus.emit('resource:update', { resource: this.signUp as SignUp });
+   eventBus.emit('resource:error', { resource: this.signUp as SignUp, error: 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.

Suggested change
resetSignIn(): void {
this.signIn = new SignIn(null);
// Cast needed because this.signIn is typed as SignInResource (interface), not SignIn (class extending BaseResource)
eventBus.emit('resource:error', { resource: this.signIn as SignIn, error: null });
}
resetSignUp(): void {
this.signUp = new SignUp(null);
// Cast needed because this.signUp is typed as SignUpResource (interface), not SignUp (class extending BaseResource)
eventBus.emit('resource:error', { resource: this.signUp as SignUp, error: null });
}
resetSignIn(): void {
this.signIn = new SignIn(null);
eventBus.emit('resource:update', { resource: this.signIn as SignIn });
eventBus.emit('resource:error', { resource: this.signIn as SignIn, error: null });
}
resetSignUp(): void {
this.signUp = new SignUp(null);
eventBus.emit('resource:update', { resource: this.signUp as SignUp });
eventBus.emit('resource:error', { resource: this.signUp as SignUp, error: null });
}
🤖 Prompt for AI Agents
In `@packages/clerk-js/src/core/resources/Client.ts` around lines 97 - 107,
resetSignIn() and resetSignUp() currently only emit 'resource:error' so the
resource signals (signInResourceSignal/signUpResourceSignal) are not updated;
after creating the new instance and emitting the error event, also emit a
'resource:update' event via eventBus.emit('resource:update', { resource:
this.signIn as SignIn }) and similarly for this.signUp (cast as needed) so
State.onResourceUpdated runs and the resource signals reflect the new reset
instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants