Bohdan
Bohdan
TTCTheo's Typesafe Cult
Created by terlan8892 on 4/28/2024 in #questions
how to import server action function to client component from file that has "server-only" package?
Think this way: You write server-side code (RSC) by default and have direct access to whatever you need, be it DB, external services or .env secrets. Everything is rendered on server and send to the client as markup. So far none of the JS you write gets shipped to the client, all without any need for "use server" or "server-only". If you need some code to run client-side (primarily to have state and interactivity via hooks), you can opt into this with "use client". Think an interactive island in a sea of "static" markup. A client component will be run (rendered) twice: first on server, generating markup, just like the code outside of the island, then sent over the wire as a bundle that consists of its markup (that we just generated) + its JS code. The JS code will then run for the second time, adding bindings (like event listeners) to the markup. This second execution is called hydration. In order to pass data to client-side islands, you can pass it as a prop from an RSC. It will be used for the initial pre-hydration rendering, then serialized and sent to client for hydration. Now we also need to take care of the communication from client-side islands back to the server. This is where "use server" comes into play. It allows you to expose a server function to your client components, which you can then either directly import in client components or pass as a prop from a server component. import "server-only" marks a module's contents as truly server only. If you attempt to import such a module in a client component, it won't work. Note that this explanation doesn't cover using server actions in RSC forms as this would be too much all at once.
15 replies
TTCTheo's Typesafe Cult
Created by terlan8892 on 4/28/2024 in #questions
how to import server action function to client component from file that has "server-only" package?
they are actually opposites: "use-server" marks a server side function or an entire module (file) as callable from the client. an http handler will be created under the hood for that. "server-only" ensures that a module will never be directly used from the client. basically, if you try to import a "server-only" module in a "use client" module, the import won't work.
15 replies
TTCTheo's Typesafe Cult
Created by terlan8892 on 4/29/2024 in #questions
Why Theo was able to import "server-only" trpc api in a client component?
your first screenshot is from the file ~/trpc/server, while the code on the second screenshot imports from ~/trpc/react
4 replies
TTCTheo's Typesafe Cult
Created by terlan8892 on 4/28/2024 in #questions
how to import server action function to client component from file that has "server-only" package?
what do you want to achieve with "server-only"? looks like an XY problem to me
15 replies
TTCTheo's Typesafe Cult
Created by hellyeah on 4/25/2024 in #questions
Next.js as a client API choice
you'd even be able to reduce the load on the main backend with nextjs caching
12 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
I suggest we move this discussion to #tech-discussion which seems to be a more appropriate place for it
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
I'm mostly referring to the TkDodo article series - its an invaluable source of information once you kinda know what you're doing, but they made next to 0 sense to me before I started building something with react query
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
but beware that many of these concepts may be all chinese to you before you actually apply them, and it's completely normal
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
so ideally you'll want to build something (even if it's small) with React Query first
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
you'll need to understand it to be able to use tRPC effectively. I initially jumped straight into tRPC without having a solid grasp on what problems React Query solves and it wasn't fun
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
I agree that what they wrote is not really constructive but 1) I fail to see how that's against the rules 2) there are better ways to call this out
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
@nyx (Rustular DevRel) @Anna | DevMiner (Rustular CCO) guys I genuinely don't get your reaction, I don't see how JokuVaan was toxic in any way to anyone here, they merely stated their opinion and adviced against my advice which I find completely fine
29 replies
TTCTheo's Typesafe Cult
Created by young T on 4/26/2024 in #questions
T3 Roadmap? What would you recommend?
hot take: if you have 2 weeks to spare, learn some Golang and build a couple APIs with it before you dive into nodejs/trpc/nextjs api folder. Golang is very minimalistic so you can get to practice very quickly, and it's great for learning "proper backend" that you will then be able to apply in TS
29 replies
TTCTheo's Typesafe Cult
Created by Vision2023 on 4/25/2024 in #questions
Should I report a bug to a federal(-ish) university without hopes of a bug bounty?
be a virtuous person and report it to them regardless of the perceived chances of getting a bounty :poohheh:
2 replies
TTCTheo's Typesafe Cult
Created by hellyeah on 4/25/2024 in #questions
Next.js as a client API choice
(btw also look into unstable_cache, it was the missing puzzle piece to me and it all clicked after I learned about it)
12 replies
TTCTheo's Typesafe Cult
Created by hellyeah on 4/25/2024 in #questions
Next.js as a client API choice
basically your server actions and query functions would act as thin wrappers around calls to the separate api, which allows you to use all the bleeding edge features like revalidatePath/revalidateTag
12 replies
TTCTheo's Typesafe Cult
Created by hellyeah on 4/25/2024 in #questions
Next.js as a client API choice
I actually think all of the nextjs features can be used, with the only difference to owning the business logic being that in the server directory you would just proxy requests to that separate api instead of implementing the logic yourself
12 replies
TTCTheo's Typesafe Cult
Created by Gus on 4/25/2024 in #questions
Fork bomb
out of mana? :theowat:
4 replies
TTCTheo's Typesafe Cult
Created by albatroz on 4/25/2024 in #questions
Communication with server and client <nextjs>
here's an in-depth explanation of the polling approach https://youtu.be/ZPh2Hapjd64?si=pAKZhQnA8e2_ZYm1
24 replies
TTCTheo's Typesafe Cult
Created by albatroz on 4/25/2024 in #questions
Communication with server and client <nextjs>
if this webhook happens as a consequence of a client side action, you could do polling i.e. make a request to the backend every N seconds to check for your api action
24 replies