Next.js Discord

Discord Forum

Server actions doesn't work in production in Vercel

Answered
Pyramid ant posted this in #help-forum
Open in Discord
Pyramid antOP
footer.tsx

import 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 &copy; {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.ts

export 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.
Answered by Common House-Martin
add revalidatePath("/") before returning
View full answer

28 Replies

@Pyramid ant `footer.tsx` jsx import 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 &copy; {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.ts` ts export 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.
try putting
export const dynamic = 'force-dynamic'

st the top level of your component
you can also try putting "use server" in the top of data.ts, for example doing
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
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
@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

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
Common House-Martin
its gotta be a cache issue
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 works
Aight
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)