TanStackT
TanStack13mo ago
2 replies
forward-apricot

Unexpected Behavior with Unused Server Function in TanStack Start

Hi everyone!
I’m facing an issue where an unused function is causing my application to misbehave. Specifically, when I include the following authenticateUserWithoutAPI function in my code, even if I don’t call it in any beforeLoad or other route handlers, it causes problems like:

1. The Clerk sign-in component not rendering.
2. The TanStack Router dev tools disappearing.

I have in one file functions/users.ts this:
export const authenticateUser = createServerFn({ method: "GET" }).handler(async () => {
  try {
    return { success: true };
  } catch (error) {
    console.log(error);
    return { status: 500 };
  }
});

export const authenticateUserWithoutAPI = async () => {
  await db.select().from(usersTable);

  throw redirect({ to: "/" });
};


If I comment out function authenticateUserWithoutAPI entirely, everything works as expected. I’m not using it anywhere directly, so I’m confused why its presence alone is affecting the behavior of my app. I only use authenticateUser in beforeLoad. I suppose the problem is using database in function directly. If I use it in "createServerFn" it's okay.

Has anyone experienced this, or is there something in TanStack Start that might be causing this issue? What Am I missing?

Important to mention the problem is in development environment.

Thank you, in advance.
Was this page helpful?