Skip to content

Commit 131c0a7

Browse files
committed
perf: ⚡️ upgraded version of tRPC and @tanstack/react-query
1 parent b19cfa1 commit 131c0a7

File tree

31 files changed

+215
-300
lines changed

31 files changed

+215
-300
lines changed

apps/web/next.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ const nextConfig = {
2525
},
2626
// Configure `pageExtensions` to include MDX files
2727
pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
28-
transpilePackages: ["@convoform/ui", "@convoform/db"],
28+
transpilePackages: ["@convoform/ui", "@convoform/db", "@convoform/api"],
2929
webpack: (config, { isServer }) => {
3030
if (isServer) {
3131
config.plugins = [...config.plugins, new PrismaPlugin()];
3232
}
3333

3434
return config;
3535
},
36+
/** We already do linting and typechecking as separate tasks in CI */
37+
eslint: { ignoreDuringBuilds: true },
38+
typescript: { ignoreBuildErrors: true },
3639
};
3740

3841
const withMDX = createMDX({

apps/web/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
"@mdx-js/react": "^3.0.0",
2525
"@next/mdx": "^14.1.0",
2626
"@sentry/nextjs": "^7.91.0",
27-
"@tanstack/react-query": "^4.36.1",
2827
"@tremor/react": "^3.13.3",
29-
"@trpc/client": "^10.43.6",
30-
"@trpc/next": "^10.43.6",
31-
"@trpc/react-query": "^10.43.6",
32-
"@trpc/server": "^10.43.6",
28+
"@tanstack/react-query": "^5.18.1",
29+
"@trpc/client": "11.0.0-next-beta.264",
30+
"@trpc/react-query": "11.0.0-next-beta.264",
31+
"@trpc/server": "11.0.0-next-beta.264",
3332
"@types/mdx": "^2.0.10",
3433
"ai": "^2.2.26",
3534
"clsx": "^2.0.0",

apps/web/src/app/(privatePage)/(formEditorPage)/forms/[formId]/conversations/[conversationId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Props = {
1010
export default async function ConversationDetailPage(props: Props) {
1111
const { conversationId } = props.params;
1212

13-
const conversation = await api.conversation.getOne.query({
13+
const conversation = await api.conversation.getOne({
1414
id: conversationId,
1515
});
1616

apps/web/src/app/(privatePage)/(formEditorPage)/forms/[formId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import FormPreview from "@/components/formEditorPage/formPreview";
2020
import NavLinks from "@/components/formEditorPage/navLinks";
2121
import { cn } from "@/lib/utils";
22-
import { api } from "@/trpc/client";
22+
import { api } from "@/trpc/react";
2323

2424
type Props = {
2525
params: { formId: string };

apps/web/src/app/(privatePage)/(mainPage)/workspaces/[workspaceId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default async function WorkspacePage({
2222
params: { workspaceId },
2323
}: Readonly<Props>) {
2424
const orgId = getOrganizationId();
25-
const workspace = await api.workspace.getOne.query({ id: workspaceId });
25+
const workspace = await api.workspace.getOne({ id: workspaceId });
2626

2727
if (!workspace) {
2828
notFound();

apps/web/src/app/(publicPage)/(formSubmissionPage)/view/[formId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const metadata: Metadata = {
1414

1515
export default async function FormViewPage({ params }: FormViewerPageProps) {
1616
const { formId } = params;
17-
const formData = await api.form.getOne.query({ id: formId });
17+
const formData = await api.form.getOne({ id: formId });
1818
if (!formData || !formData.isPublished) {
1919
notFound();
2020
}

apps/web/src/app/api/form/[formId]/conversation/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function POST(
2424
// const { isPreview } = reqPayload;
2525
const isPreview = false;
2626

27-
const form = await api.form.getOneWithFields.query({
27+
const form = await api.form.getOneWithFields({
2828
id: params.formId,
2929
});
3030

@@ -39,7 +39,7 @@ export async function POST(
3939
if (form.id !== "demo") {
4040
// get all conversations count for current organization
4141
const totalSubmissionsCount =
42-
await api.conversation.getResponseCountByOrganization.query({
42+
await api.conversation.getResponseCountByOrganization({
4343
organizationId: form.organizationId,
4444
});
4545

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
import { type NextRequest } from "next/server";
2-
import { getAuth } from "@clerk/nextjs/server";
3-
import { appRouter } from "@convoform/api/src/router/root";
4-
import { createTRPCContext } from "@convoform/api/src/trpc";
2+
import { appRouter, createTRPCContext } from "@convoform/api";
53
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
64

5+
// export const runtime = "edge";
6+
77
/**
8-
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
9-
* handling a HTTP request (e.g. when you make requests from Client Components).
8+
* Configure basic CORS headers
9+
* You should extend this to match your needs
1010
*/
11+
function setCorsHeaders(res: Response) {
12+
res.headers.set("Access-Control-Allow-Origin", "*");
13+
res.headers.set("Access-Control-Request-Method", "*");
14+
res.headers.set("Access-Control-Allow-Methods", "OPTIONS, GET, POST");
15+
res.headers.set("Access-Control-Allow-Headers", "*");
16+
}
1117

12-
const createContext = async (req: NextRequest) => {
13-
return createTRPCContext({
14-
headers: req.headers,
15-
auth: getAuth(req),
18+
export function OPTIONS() {
19+
const response = new Response(null, {
20+
status: 204,
1621
});
17-
};
22+
setCorsHeaders(response);
23+
return response;
24+
}
1825

19-
const handler = (req: NextRequest) =>
20-
fetchRequestHandler({
26+
const handler = async (req: NextRequest) => {
27+
const response = await fetchRequestHandler({
2128
endpoint: "/api/trpc",
22-
req,
2329
router: appRouter,
24-
createContext: () => createContext(req),
30+
req,
31+
createContext: () => createTRPCContext(),
2532
onError:
2633
process.env.NODE_ENV === "development"
2734
? ({ path, error }: any) => {
@@ -32,4 +39,8 @@ const handler = (req: NextRequest) =>
3239
: undefined,
3340
});
3441

42+
setCorsHeaders(response);
43+
return response;
44+
};
45+
3546
export { handler as GET, handler as POST };

apps/web/src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Toaster } from "@convoform/ui/components/ui/toaster";
77

88
import GoogleAnalytics from "@/components/googleAnalytics";
99
import { cn } from "@/lib/utils";
10-
import { TRPCReactProvider } from "@/trpc/provider";
10+
import { TRPCReactProvider } from "@/trpc/react";
1111
import { roboto } from "./fonts";
1212

1313
export const metadata: Metadata = {

apps/web/src/components/formEditorPage/conversations/conversationsSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "@convoform/ui/components/ui/sheet";
1212
import { Menu } from "lucide-react";
1313

14-
import { api } from "@/trpc/client";
14+
import { api } from "@/trpc/react";
1515
import NavLinks from "../navLinks";
1616
import { ConversationsCard } from "./conversationsListCard";
1717

0 commit comments

Comments
 (0)