Theo's Typesafe Cult

TTC

Theo's Typesafe Cult

Join the community to ask questions about Theo's Typesafe Cult and get answers from other members.

Join

Subteams design model

Hey everyone, got inspired by the post on bullet train https://blog.bullettrain.co/teams-should-be-an-mvp-feature/. And got interested how to model Team having subteams?

Vercel builds errorring out due to Invalid Vercel URL.

Hi! Stuck during first deployment of my T3 app. It keeps saying the VERCEL_URL is invalid but looking at the env variables the VERCEL_URL is set and is set to https://**.vercel.app VERCEL_URL: z.string().url().optional(),...

NextJS Intercepting routes

Hi there, Been playing with the fancy new intercepting routes within Next and I need a 1am-programming-stupidity check. Am I wrong to assume that this should be intercepting /dashboard/post ?...

best practices to throw error on backend

I see people using throw new error and throw error But for me i kinda prefer having standard patterns across all the apis ``` return {...

how to access Nested routes

```ts export const appRouter = t.router({ show: t.procedure.query(async () => { const cities: Cities[] = await db.select().from(city); return cities;...

extending trpc middleware

When making a procedure with middleware, is there any difference between using .unstable_pipe() to extend an existing middleware and then .use() versus just .use() on an existing procedure using the existing middleware?

react-image-magnifier

Whats the best lib for Next js Image tag? https://www.npmjs.com/package/react-image-magnifiers Isnt working. ```js <Image...

App dir revalidate doesn't work on static routes

Hey guys, anyone knows why revalidate doesn't work on next 13.4.12 app dir ? i read that there's a problem with dynamic routes but in my case im using a static route '/browse' and it still doesn't rebuild the page. I used export const revalidate = 30 and used fetch with { next : { revalidate : 30 } } and nothing works.

Help using Zustand and Pusher on the edge

I am trying to allow users on my Vercel deployed website to subscribe to Pusher messages. I understand that this isn't normally possible due to how the edge works. From looking at the Zapdos repository I can see that it's possible to use Zustand to maintain a connection to Pusher on an edge deployment. I've included screenshots of my Zustand store - on the left file I use the pusher store, then I have a useEffect that starts binding events when the room is defined....

tRPC in nextjs Capacitor app

is it possible to have tRPC in app like this? Capacitor uses an exported static next app so it wont have access to server req/res for trpc contexts. But is it possible to use it for just a wrapper with react-query? I don't believe you can use next auth in an app like this for similar reasons, but I think its possible to use trpc

I have TRPC question/problem

This works fine ```ts getUser: publicProcedure .input(z.object({ id: z.string()})) .query(({ ctx ,input }) => {...
Solution:
npx prisma db push, restart your ide, should fix it

How to prefetch queries with tRPC?

The generateSSGHelpers function is deprecated as of now, what is the new way to prefetch queries with trpc?

revalidatePath invalidates all route cache

Is this a known bug? I see no one mention it yet but calling revalidatePath in a server actions invalidates all route cache not just the one specified.

How to add one-off scripts to a T3 app

I started my project with create-t3-app a long time ago. i see that they've added the new t3 env-next module for managing environment variables in a typesafe way and i decided to switch to it. However, this seems to have broken my scripts directory which can no longer run one-off db scripts because its now importing a .mjs module. What is the recommended way to run one-off typescript scripts in a ct3a project?

Error validating: You defined the enum `UserRole`. But the current connector does not support enums.

Solution:
Looks like you're using sqlite. You can: * have a UseRole table * if your project isn't that complex/big, you can just just store it as a string * isAdmin boolean (if that's all you'll need)?...

running vercel edge api functions?

Trying to use vercel edge functions for my trpc api routes. Having a hard time with this. Any advice?

How to deploy API to Vercel

What's the easiest way to deploy a basic API endpoint to Vercel? I made an Express app structured like: ``` api...
Solution:
solved (solution is specific for my needs) ```ts import { type File, type Files, IncomingForm } from 'formidable' const form = new IncomingForm({ multiples: false })...

How to handle Prod and Dev in Vercel.

Hey everyone, I've been using Vercel to host web apps for a decent amount of time. But I still can't figure out a way to separate prod from dev on deployments. Let's say I have a github repo with a main and dev branches....
Solution:
you can set the main branch in the settings for production deployments

Drizzle vs. Prisma: why does Drizzle need less row reads?

I deployed a project to PlanetScale and noticed a high number of row reads for searching a table of 500 rows. I didn't think anything of it. I've been wanting to switch to Drizzle ORM anyway after I saw the TypeScript schema definition. I made the switch with everything the same (except I'm not sorting by id) and noticed a HUGE rise in read/return efficiency with Drizzle. The SQL query is the same. The indices are the same. I did notice Prisma prepends the db name and table everywhere, like db.Table.column wherever it can. Drizzle doesn't. I'm impressed. Is there anything I'm missing? ...
Solution:
Yeah, prisma doest use joins, it makes individual calls and combines the data.

Drizzle type question

I swapped over to Drizzle, and I've got this schema right ```ts export const User = mysqlTable('users', { id: serial('id').primaryKey(),...
Solution:
And limit 1 still returns an array btw. So you have to do data[0].sessions