javascript icon indicating copy to clipboard operation
javascript copied to clipboard

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

Open paperclover opened this issue 2 months ago • 2 comments

Preliminary Checks

  • [x] I have reviewed the documentation: https://clerk.com/docs

  • [x] I have searched for existing issues: https://github.com/clerk/javascript/issues

  • [x] I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)

  • [x] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.

Reproduction

https://github.com/paperclover/bug-reproductions/tree/tanstack-start-clerk-redirection

Publishable key

pk_test_Z2xvcmlvdXMtcGVnYXN1cy00LmNsZXJrLmFjY291bnRzLmRldiQ

Description

Steps to reproduce:

  • npm i
  • npm run dev
  • open
  • click "Sign In"
  • click "go home"

Expected behavior:

clerk should not redirect me when i click a link to /

Actual behavior:

clerk issues a faulty redirect to /login#/?redirect_url=http%3A%2F%2Flocalhost%3A3001%2F

at work, we have a patch to prevent this from happening, but this is a really bad bug that affects anyone using the sign in page component. additionally, we are facing issues where clerk will redirect us between our staging domain and our production domain (like https://staging.example.com and https://example.com) which is making it hard to test bug fixes before deploying.

diff --git a/dist/client/useAwaitableNavigate.js b/dist/client/useAwaitableNavigate.js
index 37c57d8d391f2430f19eae648c19b9a124fbedb4..1bb6583c396dabd530382eb6aedb289b9df56666 100644
--- a/dist/client/useAwaitableNavigate.js
+++ b/dist/client/useAwaitableNavigate.js
@@ -1,5 +1,5 @@
-import { useNavigate, useLocation } from '@tanstack/react-router';
-import React, { useTransition } from 'react';
+import { useLocation, useNavigate } from "@tanstack/react-router";
+import React, { useTransition } from "react";
 
 // src/client/useAwaitableNavigate.ts
 var useAwaitableNavigate = () => {
@@ -15,6 +15,22 @@ var useAwaitableNavigate = () => {
     resolveAll();
   }, [location]);
   return (options) => {
+    // this is a workaround for a bug in clerk where if you attempt to navigate
+    // away from the signin page and the load takes too long, clerk gets
+    // confused and tries to redirect you back. since clover is low on time,
+    // this hack prevents the navigation but not the root cause.
+    //
+    // furthermore, it appears we are going to rebuild the signup page anyways.
+    //
+    // TODO: report this upstream
+    if (
+      !location.pathname.startsWith("/signin") &&
+      !location.pathname.startsWith("/signup") &&
+      !location.pathname.startsWith("/@")
+    ) {
+      return Promise.resolve();
+    }
+
     return new Promise((res) => {
       startTransition(() => {
         resolveFunctionsRef.current.push(res);

Environment

System:
    OS: macOS 26.1
    CPU: (14) arm64 Apple M4 Pro
    Memory: 4.21 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.5.0 - /etc/profiles/per-user/clo/bin/node
    npm: 11.5.1 - /etc/profiles/per-user/clo/bin/npm
    bun: 1.3.0 - /etc/profiles/per-user/clo/bin/bun
    Deno: 2.4.3 - /etc/profiles/per-user/clo/bin/deno
  Browsers:
    Chrome: 142.0.7444.176
    Safari: 26.1
  npmPackages:
    @clerk/tanstack-react-start: ^0.27.6 => 0.27.6
    @tailwindcss/postcss: ^4.1.17 => 4.1.17
    @tanstack/react-router: ^1.139.14 => 1.139.14
    @tanstack/react-router-devtools: ^1.139.14 => 1.139.14
    @tanstack/react-start: ^1.139.14 => 1.139.14
    @types/node: ^24.10.1 => 24.10.1
    @types/react: ^19.2.7 => 19.2.7
    @types/react-dom: ^19.2.3 => 19.2.3
    @vitejs/plugin-react: ^5.1.1 => 5.1.1
    react: ^19.2.1 => 19.2.1
    react-dom: ^19.2.1 => 19.2.1
    typescript: ^5.9.3 => 5.9.3
    vite: ^7.2.6 => 7.2.6
    vite-tsconfig-paths: ^5.1.4 => 5.1.4

paperclover avatar Dec 04 '25 01:12 paperclover