Next.js Discord

Discord Forum

DB query not updating with NextJS and Vercel

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I have a NextJS app connected with Supabase up and running and on localhost I am able to change data in DB and see changes reflected (with hard refresh).

I also have the same app deployed on Vercel and changes to DB are not reflected there even with hard refresh.

I tried reading about caching on Vercel and I wasn't able to really understand too much.

Does anyone know how I may be able to fix this?

Here is my code which is fetching data in question:

import { supabase } from "../lib/supabaseClient";

export default async function Home() {
  // Fetch data from Supabase in a server-side function
  const { data: users, error } = await supabase.from("users").select("*");

  if (error) {
    console.error("Error fetching users:", error);
    return (
      <div>
        <h1>Error Fetching Users</h1>
        <p>{error.message}</p>
      </div>
    );
  }

  return (
    <div>
      <h1>Users List</h1>
      {users && users.length > 0 ? (
        <ul>
          {users.map((user) => (
            <li key={user.id}>{user.name}</li>
          ))}
        </ul>
      ) : (
        <p>No users found</p>
      )}
    </div>
  );
}
Answered by gin
follow this guide and after u are done remove "use client" directive from your layout.tsx
View full answer

31 Replies

West African LionOP
sure, one sec
do you mean the build logs?
yup
West African LionOP
@West African Lion https://gist.github.com/pivcec/779d9aad996e89ec44ecab5b2452b6fa
can u try opting out of pre-rendering using this ->
export const dynamic = 'force-dynamic'

Place this in your page.tsx or layout.tsx
this will cause next to rerender rsc components on request
for that route
West African LionOP
thanks, have added in this manner and will try to redeploy and test now: https://gist.github.com/pivcec/c481146cdf5acc7081cdd5df5d3e275b
👍
West African LionOP
same behaviour after deploying

here is build log: https://gist.github.com/pivcec/98b8c5cde49de28098b42d949692892f
check this
i noticed u are using deprecated libraries
follow this guide and after u are done remove "use client" directive from your layout.tsx
Answer
West African LionOP
thanks
sorry, was on phone for a bit
deprecated libs.. I guess that's one hazard of asking chatgpt for instructions
thanks for pointing out.. will work to resolve that also
West African LionOP
well, I followed that guide but now I have a new problem.. a cookie is being created on sign in but I don't see any example code anywhere showing how to handle that cookie in my nextjs code in order to evaluate if session exists, get data from session etc
so.. I could still push what I have so far just to test if it somehow alleviates the original issue regarding stale data
come to think of it
West African LionOP
@gin I rewrote all the auth stuff using the guide that you pointed me to and changes to DB are also being reflected on deployed version now
thanks
West African LionOP
sure.. how do I do that exactly?