I created T3-app and my build fail on timeout error. If I change this line:
const [leads] = api.lead.getLeads.useSuspenseQuery();
to
const { data: leads } = api.lead.getLeads.useQuery();
the build pass.
How can I use useSuspenceQuery? What am I doing wrong? Besides not having a loading/error state, is there any other benefit of suspenceQuery?
the complete error:
Failed to build /page: / (attempt 1 of 3) because it took more than 60 seconds. Retrying again shortly.
Failed to build /page: / (attempt 2 of 3) because it took more than 60 seconds. Retrying again shortly.
Failed to build /page: / after 3 attempts.
Export encountered an error on /page: /, exiting the build.
⨯ Static worker exited with code: 1 and signal: null
this is the page component:
import { api, HydrateClient } from "@/trpc/server";
import { Leads } from "./_components/Leads/Leads";
export default async function Home() {
await api.lead.getLeads.prefetch();
return (
<HydrateClient>
<Leads />
</HydrateClient>
);
}
This is the leads table component where the useSuspenseQuery is at:
"use client";
import { api } from "@/trpc/react";
import { Table } from "../../UI";
import { columns } from "./LeadsTable.columns";
export const LeadsTable = () => {
const [leads] = api.lead.getLeads.useSuspenseQuery();
return (
<Table
rows={leads}
columns={columns}
initialState={{
sorting: {
sortModel: [
{
field: "id",
sort: "desc",
},
],
},
}}
/>
);
};
This is the entire repo: https://github.com/ItayTur/sohnim-io
useQueryfetches data on the client, so your page will be statically generated (if eligible) without data. On the other hand,useSuspenseQueryfetches data on both the server and the client, meaning your page will be statically generated (if eligible) with data. Refer to this answer for more details. Your backend server might be blocking requests from the Node.js server, or there could be something preventing the Node.js server from sending requests.useSuspenseQueryin your Next.js app using the App Router and tRPC is likely due to the way Suspense and server-side rendering (SSR) interact. When usinguseSuspenseQuery, the component expects the data to be available immediately, and if it's not, it will suspend the rendering until the data is fetched. This can cause issues during the build process, especially if the data fetching takes too long or if it's not available at build time. I will provide an answer asap