Server actions doesn't work in production in Vercel
Answered
Pyramid ant posted this in #help-forum
Pyramid antOP
footer.tsximport styles from "./styles.module.scss";
import Logo from "@/components/Logo/Logo";
import Link from "next/link";
import { getInfo } from "@/functions/data";
const Footer = async () => {
const socials = await getInfo();
return (
<Reveal>
<div className={styles.footer}>
<div className={styles["content"]}>
<div className={styles["left"]}>
<Reveal>
<p className={styles["copyright"]}>
The Formante © {new Date().getFullYear()}
</p>
</Reveal>
<Reveal>
<p className={styles["copyright"]}>
Designed by {INFO.designedBy}
</p>
</Reveal>
</div>
<div className={styles["right"]}>
<div className={styles["contact-info"]}>
<Reveal>
<div className={styles["contact-group"]}>
<p className={styles["title"]}>Email</p>
<p className={styles["label"]}>
{socials
? !socials.email
? INFO.email
: socials.email
: INFO.email}
</p>
</div>
</Reveal>
</div>
</div>
</div>
</Reveal>
);
};
export default Footer;data.tsexport async function getInfo() {
try {
const socials = await prisma.information.findFirst({});
return socials;
} catch (error) {
console.error("Error in getInfo:", error);
return {
_id: "",
youtube: "",
spotify: "",
apple: "",
email: "",
instagram: "",
phone: "",
twitter: "",
};
}
}This works as expected in development, but in production, it doesnt update the data where there are changes in the values. It just shows the values which were there while the deployment.
28 Replies
you can also try putting
"use server" in the top of data.ts, for example doingexport async function getInfo() {
"use server";
try {
const socials = await prisma.information.findFirst({});
return socials;
} catch (error) {
console.error("Error in getInfo:", error);
return {
_id: "",
youtube: "",
spotify: "",
apple: "",
email: "",
instagram: "",
phone: "",
twitter: "",
};
}
}@!=tgt you can also try putting `"use server"` in the top of data.ts, for example doing
ts
export async function getInfo() {
"use server";
try {
const socials = await prisma.information.findFirst({});
return socials;
} catch (error) {
console.error("Error in getInfo:", error);
return {
_id: "",
youtube: "",
spotify: "",
apple: "",
email: "",
instagram: "",
phone: "",
twitter: "",
};
}
}
Pyramid antOP
Yeah, but i had to put it in the top of the data.ts file instead of tinside the functions, but i might be wrong
But i'll give this a shot
Pyramid antOP
I've done that but still doesn't seem to work :/
Common House-Martin
add revalidatePath("/") before returning
Answer
Common House-Martin
maybe?
@Pyramid ant I've done that but still doesn't seem to work :/
Does this work locally when you run npm run build and npm start
@Anay-208 Does this work locally when you run npm run build and npm start
Pyramid antOP
Yes it does.
@Common House-Martin add revalidatePath("/") before returning
Pyramid antOP
hmmm I havent tried this yet, but i'll give it a shot
@Pyramid ant Yes it does.
What exactly is the result right now?
Is the footer being displayed?
Pyramid antOP
The root page (the home page)
funny thing is, i tried creating a test page to check if it works
this surprising works in deployment without
import { getInfo } from "@/functions/data";
const page = async () => {
const socials = await getInfo();
console.log(socials);
return <div>{socials?.apple} - test</div>;
};
export default page;this surprising works in deployment without
force-dynamic or anything additionalCommon House-Martin
its gotta be a cache issue
@Pyramid ant funny thing is, i tried creating a test page to check if it works
tsx
import { getInfo } from "@/functions/data";
const page = async () => {
const socials = await getInfo();
console.log(socials);
return <div>{socials?.apple} - test</div>;
};
export default page;
this surprising works in deployment without `force-dynamic` or anything additional
What is the error you see in production
Pyramid antOP
There's no error.
It works in that page alone.
but it doesn't work in any other pages
I'll try the
revalidatePath function i'll see if this worksAight
Pyramid antOP
Seems like revalidating the path works!
Thank you guys!
Pyramid antOP
But i want to know why this doesn't happen in development but it happens when its in production?
Common House-Martin
i recommend reading cache section of the docs and watching videos about people complaining about nextjs caching so you understand its ups and downs better
also mark my answer as solved pls :v)