Do server actions get sent to the client?
Answered
Piping Plover posted this in #help-forum
Piping PloverOP
I'm reading the docs on server actions right now and I'm a little confused. Do server actions get sent to the client as part of the bundle?
For example, if I have this:
1.
Would Page include the server action in the bundle?
2. What if you inline the server action? Does it get sent in the bundle then?
For example, if I have this:
1.
// actions.ts
'use server';
import prisma from '@/lib/prisma';
export async function handleClick() {
return await prisma.post.delete({
where: {
id: 1,
},
});
}// page.tsx
import { handleClick } from '@/actions/actions';
export default function Page() {
return (
<div>
<h1>Home page</h1>
<button
onClick={handleClick}
>
Button
</button>
</div>
);
}Would Page include the server action in the bundle?
2. What if you inline the server action? Does it get sent in the bundle then?
// page.tsx
import prisma from '@/lib/prisma';
export default function Page() {
return (
<div>
<h1>Home page</h1>
<button
onClick={async () => {
'use server'
await prisma.post.delete({
where: {
id: 1,
}
})
}}
>
Button
</button>
</div>
);
}Answered by joulev
server actions are not sent to the client but the way to trigger server actions are sent to the client.
so anyone can trigger the server actions, but no one can sniff what goes on inside the server action function.
so anyone can trigger the server actions, but no one can sniff what goes on inside the server action function.
1 Reply
@Piping Plover I'm reading the docs on server actions right now and I'm a little confused. Do server actions get sent to the client as part of the bundle?
For example, if I have this:
1.
ts
// actions.ts
'use server';
import prisma from '@/lib/prisma';
export async function handleClick() {
return await prisma.post.delete({
where: {
id: 1,
},
});
}
tsx
// page.tsx
import { handleClick } from '@/actions/actions';
export default function Page() {
return (
<div>
<h1>Home page</h1>
<button
onClick={handleClick}
>
Button
</button>
</div>
);
}
Would Page include the server action in the bundle?
2. What if you inline the server action? Does it get sent in the bundle then?
tsx
// page.tsx
import prisma from '@/lib/prisma';
export default function Page() {
return (
<div>
<h1>Home page</h1>
<button
onClick={async () => {
'use server'
await prisma.post.delete({
where: {
id: 1,
}
})
}}
>
Button
</button>
</div>
);
}
server actions are not sent to the client but the way to trigger server actions are sent to the client.
so anyone can trigger the server actions, but no one can sniff what goes on inside the server action function.
so anyone can trigger the server actions, but no one can sniff what goes on inside the server action function.
Answer