Rivenris
Rivenris
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Benfa on 3/4/2025 in #questions
Cache issue
1. Wrap select in unstale_cache, not insert. Insert should revalidateTag but selecting is what should actually be cached. 2. Have you tried adding export const dynamic = 'force-dynamic' above the page? This will prevent static generation of the page. Your data cache should still be used fine.
4 replies
TTCTheo's Typesafe Cult
Created by sl8er on 2/23/2025 in #questions
Dependent select boxes in form
How does the value change in the options object? Does the reference to options/data update when your values inside change from within the code?
2 replies
TTCTheo's Typesafe Cult
Created by msobkyy on 2/15/2025 in #questions
Trojan Virus in React Project!!
False positives in scanners are possible, but I'd be extra carefull. It's not like python + node are rare combinations, but I don't like python being installed automatically. At this point simply resolve it with repo author, who invited you. If you don't know them and it seems fishy, drop the job and report the repo.
12 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Although, in the table there are multiple Login buttons in each row, actually I'll send you the original UI in the DMs
Shouldn't be a problem here. I used Clerk which provides it's own login button in similar way, where the login button was placed all over the page. You can still handle it with one server action, used accross multiple components.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
In general, await in Next 15 is the way for Next to think "Ok, let's send what we have for now, and from now on stream the lower part of the tree once promise is resolved"
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Also, importing client components in a server component doesn't make it a client component right?
No, client component used in server component simply makes cutoff point for next to know where to start sending react js code to client. Server components will only have react code on server. Client will live on both.
Could you decipher why Next.js is behaving the way it is? Because oddly enough, I used to get Table Headers in the HTML itself before but after a few changes it stopped happening and even the table headers became client side rendered.
The thing to remember is that async call will delay the html and push it into stream afterwards. Previously you had axios call right at the start of the page, which makes pretty much everything afterwards (including jsx/html) delayed. Pushing async call lower will make the top stuff generate asap.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Next.js UI revalidation model is phenomenal and I'd use it over client-side data state in almost all cases, because it allows you to skip update logic on client in most of the cases. That is why I choose to use server-side rendering for as much as I can.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Additionally I would suggest: - Not worrying about getting response as full html from next each time. Unless you are focusing on SEO, getting the table content indexed by bots etc. you don't need that - Use Server Actions to modify data. Then revalidate the data on server action. This will cause next to calculate the diff of html and send update to the SSR-ed UI automatically. Again, no need to worry about pushing updated data through client-side states only to show newest version after save - Push state of auth as low as you can - your page may not need to know who is logged in. Button in the navbar needs to know this, but not necessarily the page itself. It may be a bit counterintuitive as in the classic single page apps built on React you need to control where data is loaded and deduplicate those requests. On SSR-ed Next.js you don't need that if you handle your fetch cache correctly. You can push data loading as low as you wish.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Note, that I wrote everything to be server components. This is how I personally work with Next - push as much as possible to server-side. This speeds up data-loading and rendering by a lot.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
Now, the cool thing is, when you navigate from dashboard/1 to dashboard/2, next will skip rendering of the page, table head etc. and send only diff that needs to be replaced in the target - namely table rows. So you don't have to worry about deciding which html is sent when - it's done on next-side automatically.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
I gave it some thought and I thought this may give you perpective - here's how I would write this UI. Option 1: push data loading to rows component
// dashboard.tsx
async function DashboardPage(params) {
const pageNo = await (params).page;
// no data loading here, but still server comp
return <Table>
<Suspense fallback={<TableDataMock />}>
<TableDataRows page={page} />
</Suspense>
</Table>
}


// TableData.tsx
async function TableDataRows({page}) {
// We get data here
const data = await getMeData(page)
return data.map(item => <tr key={item.id}>
<td>{item.name}</td>
...
</tr>)
}
// dashboard.tsx
async function DashboardPage(params) {
const pageNo = await (params).page;
// no data loading here, but still server comp
return <Table>
<Suspense fallback={<TableDataMock />}>
<TableDataRows page={page} />
</Suspense>
</Table>
}


// TableData.tsx
async function TableDataRows({page}) {
// We get data here
const data = await getMeData(page)
return data.map(item => <tr key={item.id}>
<td>{item.name}</td>
...
</tr>)
}
In here data loading is done only in context of actual rows. Table exists outside of loaded scope, so it will show headers etc way before data is rendered. Everything is server-sided, but you can add e.g. ActionMenu component that is client-side and does some client-side things based on loaded data. Option 2: Load data table level, use the same table headers for both fallback and loaded state
// dashboard.tsx
async function DashboardPage(params) {
const pageNo = await (params).page;
// no data loading here, but still server comp
return <Suspense fallback={<TableMock />}>
<Table page={page} />
</Suspense>
}

async function Table({page}) {
const data = await getMeData(page);
return <table>
<TableHead />
{data.map(item => <tr>...</tr>)}
</table>
}

// tablehead.tsx
function TableHead() {
return <thead>
...
</thead>
}

// tablemock.tsx
function TableMock() {
return <table>
<TableHead />
<tr><td>Loading...</td></tr>
</table>
}
// dashboard.tsx
async function DashboardPage(params) {
const pageNo = await (params).page;
// no data loading here, but still server comp
return <Suspense fallback={<TableMock />}>
<Table page={page} />
</Suspense>
}

async function Table({page}) {
const data = await getMeData(page);
return <table>
<TableHead />
{data.map(item => <tr>...</tr>)}
</table>
}

// tablehead.tsx
function TableHead() {
return <thead>
...
</thead>
}

// tablemock.tsx
function TableMock() {
return <table>
<TableHead />
<tr><td>Loading...</td></tr>
</table>
}
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
@Rajneesh Mishra So, Page is SSR-ed, just not all at the same time. First, the known html blocks are sent (the original output) and after that you see a bunch of scripts at the end of html - this is next SSR streaming the content, that were added to html once axios call gets user data. In other words, first you get html that doesn't need to be delayed, and after that, using the existing request, next adds components rendered a bit later. This is expected behavior and how next deals with waiting for data response. Things to note here: 1. Axios call still happens on the server, and only added html is streamed to browser. 2. You can (and often should) introduce some form of loading indicator - e.g. using Suspense to render fallback 'skeleton' UI. (more on that here: https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense) 3. If the api url points to the same next app as the UI, I would strongly suggest replacing axios call with direct code execution on server component - I won't get into detail here unlesss you want to talk about it further.
30 replies
TTCTheo's Typesafe Cult
Created by Saitama Kun on 2/13/2025 in #questions
Why is this component not fully SSRed, how can I do it and what learnings can I take from it?
It's really hard to tell what is not going well without more details. General rule is - yes, server components go through immediately. You should see html and body tags in the response at least from the layout. Depending on your config and actual code, the dynamic content will be streamed afterwards or waited upon before nested components will show up. I'd investigate the code for bottlenecks and async calls. Also check where is the response html cutoff, because that component will probably be the issue.
30 replies
TTCTheo's Typesafe Cult
Created by lolking0 on 2/10/2025 in #questions
URGENT!! System Design Interview Prepration
Sorry to be late on this, but if components should be versioned, my immediate idea would be to extract them to separate package (it could still be in the same repo, by using monorepo structure). It's hard to provide more insight as there is no clear clue on how this versioning should impact app development.
2 replies
TTCTheo's Typesafe Cult
Created by akashamba on 2/9/2025 in #questions
TypeScript React: Confused about icon: Icon and {...}: Props syntax in component props
Exactly. If in any case you need runtime validation, you'll have to use something on top of it. E.g. zod offers that validation and is well integrated with typescript types, which makes it good proposition for extending build-time validation to runtime one.
9 replies
TTCTheo's Typesafe Cult
Created by akashamba on 2/9/2025 in #questions
TypeScript React: Confused about icon: Icon and {...}: Props syntax in component props
@akashamba I know it may be a bit outside of asked question, but I wanted to share a bit of TypeScript context: The enforcement is a very loose term in here. Your IDE and compilation process will check if the variables that will be passed in code are of correct types. This check, however, is not going to happen when the app is actually built and started. You'll have no errors thrown if label and href are not strings e.g. if loaded from file, or from external api. So it's more like IDE forces you to write a code that is type compliant.
9 replies
TTCTheo's Typesafe Cult
Created by trevdev on 2/4/2025 in #questions
When Theo says "put it in the KV", what is the KV?
@omnicoder What you are refering to are not exactly KV services. Those are all services oriented around encryption keys, storing secured and encrypted data etc. It's hardly a classical Key-Value store
6 replies
TTCTheo's Typesafe Cult
Created by trevdev on 2/4/2025 in #questions
When Theo says "put it in the KV", what is the KV?
You can use Redis for it, just remember that sometimes data in KV needs to be persisted, and redis is often used as "cache that will be cleared upon restart". Cloudflare KV is a bit slower, but still can be used. There is a bunch of KV solutions laying around, but most people would probably choose either redis, DB, Cloudflare KV, simple write-to-file solution or even keep data in memory and don't persist it.
6 replies
TTCTheo's Typesafe Cult
Created by trevdev on 2/4/2025 in #questions
When Theo says "put it in the KV", what is the KV?
KV means Key-Value, and in context of his video it is literally Key-Value store. Any KV store that is quick to access and persistable would fit what theo is doing with stripe. I mentioned persistence, because otherwise the data will need to be refetched upon restart, which may not be preferable. For example: - It can be Redis with persisted data, - it can be Cloudflare KV, - it can be a database table that is indexed by column key and allows any string in value,
6 replies