Skip to content

Conversation

@Ayush2k02
Copy link

@Ayush2k02 Ayush2k02 commented Dec 26, 2025

Summary

Fixes incorrect redirects when navigating away from sign-in/sign-up pages in TanStack React Start applications.

Problem

When users navigated away from the sign-in page (e.g., clicking "go home" to navigate to /), Clerk would issue faulty redirects to non-existent pages like /login#/?redirect_url=http%3A%2F%2Flocalhost%3A3001%2F.

The root cause was in useAwaitableNavigate: the navigation promise was being resolved immediately (res(navigate(options))) before the location actually changed. This happened because:

  1. startTransition defers the navigation
  2. But the promise was resolved immediately on line 25
  3. Clerk's redirect logic saw the promise resolve but the location hadn't changed yet
  4. Clerk thought navigation "failed" and tried to redirect again

Solution

Changed line 25 from:

res(navigate(options));

to:

navigate(options);

Now the promise is only resolved after the location actually changes (via the useEffect that watches the location), matching the behavior of the React Router implementation.

Changes

  • Modified packages/tanstack-react-start/src/client/useAwaitableNavigate.ts to remove premature promise resolution
  • Added changeset documenting the fix

Testing

The fix aligns the TanStack React Start implementation with the proven React Router implementation, which doesn't have this issue.

Fixes #7362

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where navigation away from sign-in and sign-up pages would incorrectly redirect to non-existent pages.

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

…change

Fixes incorrect redirects when navigating away from sign-in/sign-up pages.
Previously, the navigation promise was resolved immediately before the
location actually changed, causing Clerk to think navigation failed and
issue faulty redirects to non-existent pages.

Now the promise is only resolved after the location changes, matching the
behavior of the React Router implementation.

Fixes clerk#7362
@changeset-bot
Copy link

changeset-bot bot commented Dec 26, 2025

🦋 Changeset detected

Latest commit: 6e721b0

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

This PR includes changesets to release 1 package
Name Type
@clerk/tanstack-react-start 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 Dec 26, 2025

@Ayush2k02 is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

📝 Walkthrough

Walkthrough

A patch version changeset is added for the Clerk TanStack React Start package. The useAwaitableNavigate function is modified to resolve the navigation promise without passing the navigate function's return value. Previously, the promise resolved with navigate(options) result; now it resolves without that result. This change affects how the awaitable navigation promise completes while maintaining the existing control flow within startTransition and location change detection. The modification addresses redirect issues occurring when navigating away from sign-in and sign-up pages.

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing navigation promise resolution timing to occur after location changes, which directly addresses the root cause of incorrect redirects mentioned in issue #7362.
Linked Issues check ✅ Passed The code changes resolve the root cause identified in issue #7362 by ensuring navigation promises only resolve after location changes, preventing premature promise resolution that caused Clerk to issue faulty redirects.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the navigation promise resolution issue. The changeset and modification to useAwaitableNavigate.ts are both focused on the stated objective of preventing incorrect redirects.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent 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 063ab4d and 6e721b0.

📒 Files selected for processing (2)
  • .changeset/fix-tanstack-redirect-navigation.md
  • packages/tanstack-react-start/src/client/useAwaitableNavigate.ts
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{js,jsx,ts,tsx}

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

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

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

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

Use Prettier for consistent code formatting

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.ts
packages/**/src/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.ts
**/*.{ts,tsx,js,jsx}

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

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

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.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/tanstack-react-start/src/client/useAwaitableNavigate.ts
**/*.ts?(x)

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

Use proper TypeScript error types

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.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/tanstack-react-start/src/client/useAwaitableNavigate.ts
**/*.{js,ts,jsx,tsx}

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

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/tanstack-react-start/src/client/useAwaitableNavigate.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/tanstack-react-start/src/client/useAwaitableNavigate.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/tanstack-react-start/src/client/useAwaitableNavigate.ts
⏰ 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). (1)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/tanstack-react-start/src/client/useAwaitableNavigate.ts (1)

21-28: Logic change looks correct for fixing the race condition.

The promise now resolves only after the location actually changes (via the useEffect on line 17-19), rather than immediately with the navigate() return value. This correctly addresses the race condition described in the PR objectives where Clerk was detecting resolved promises before location changes.

.changeset/fix-tanstack-redirect-navigation.md (1)

1-5: Changeset looks good.

The patch-level version bump and description accurately reflect the bug fix.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

clerk/tanstack-react-start issues incorrect redirects to pages that do not exist

1 participant