Skip to content
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

Start - Await component with Date (type mismatch) #3839

Open
perfectbase opened this issue Mar 23, 2025 · 0 comments
Open

Start - Await component with Date (type mismatch) #3839

perfectbase opened this issue Mar 23, 2025 · 0 comments
Labels
revisit-after-seroval start Everything about TanStack Start

Comments

@perfectbase
Copy link

perfectbase commented Mar 23, 2025

Which project does this relate to?

Start

Describe the bug

Hey team! I think I found a bug with how the Await component handles serialization.

Here’s what’s happening:

  • If I pass a Date object directly from the loader, everything works fine — it’s recognized as a real Date.
  • But if I return a Date from a promise (e.g., via Await), the value looks like a Date in TypeScript, but it is a string at runtime.

You can reproduce it with this minimal example:

import { Await, createFileRoute } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/react-start";
import { Suspense } from "react";

const getDate = createServerFn({ method: "GET" }).handler(async () => {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  return new Date();
});

export const Route = createFileRoute("/_authed/(home)/")({
  loader: async () => {
    return {
      date: new Date(), // This stays a Date
      datePromise: getDate(), // This gets turned into a string
    };
  },
  component: Dashboard,
});

function Dashboard() {
  const { date, datePromise } = Route.useLoaderData();
  console.log("DATE", typeof date); // Logs "object" (correct)

  return (
    <Suspense fallback={<div>Loading...</div>}>
      <Await promise={datePromise}>
        {(date) => {
          console.log("DATE2", typeof date); // Logs "string", even though TS says Date
          return <div>{date}</div>;
        }}
      </Await>
    </Suspense>
  );
}

Let me know if I’m missing something.

Thanks!

Expected behavior

I believe it should be a date inside the Await component. (Or the TypeScript type should be a string)

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 1.114.27 (start)
@SeanCassiere SeanCassiere added the start Everything about TanStack Start label Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
revisit-after-seroval start Everything about TanStack Start
Projects
None yet
Development

No branches or pull requests

3 participants