JP
JP
Explore posts from servers
TTCTheo's Typesafe Cult
Created by JP on 12/6/2023 in #questions
Can't reference complex object in server action closure
Can any RSC wizards help me out here? This is very confusing to me, if i change tableSchema to be a primitive it works fine. My guess is that all of the values in the closure are serialized and sent to the client only to be sent back to the server?? If this is indeed what is happening (the error message sucks), where can i learn more about this?
// server-component.tsx
import { createInsertSchema } from "drizzle-zod";
import { posts } from "~/server/db/schema";

export async function ServerComponent() {
const tableSchema = createInsertSchema(posts);

async function action(formData: FormData) {
"use server";
console.log(tableSchema);
// ^^^^ Causes error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components.
// error goes away when commented out
console.log(formData);
}

return (
<div>
{Object.keys(tableSchema.shape).map((key) => (
<div key={key}>{key}</div>
))}
</div>
);
}
// server-component.tsx
import { createInsertSchema } from "drizzle-zod";
import { posts } from "~/server/db/schema";

export async function ServerComponent() {
const tableSchema = createInsertSchema(posts);

async function action(formData: FormData) {
"use server";
console.log(tableSchema);
// ^^^^ Causes error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components.
// error goes away when commented out
console.log(formData);
}

return (
<div>
{Object.keys(tableSchema.shape).map((key) => (
<div key={key}>{key}</div>
))}
</div>
);
}
10 replies
TTCTheo's Typesafe Cult
Created by JP on 11/5/2023 in #questions
Is there a way to load my .env from t3-env in one off scripts?
I believe that is what this issue is asking for? https://github.com/t3-oss/t3-env/issues/97
2 replies