Next.js Discord

Discord Forum

revalidatePath doesn't work how I expected

Unanswered
Nile Crocodile posted this in #help-forum
Open in Discord
Avatar
Nile CrocodileOP
This is my configuration, i would like to know if i'm doing something wrong. Let me know if need more information, but the resume is that I wanna update the DataTable
Image
Image
Image

7 Replies

Avatar
Pacific sand lance
can u give more context? u didn't show where revalidatePath is used
Avatar
Nile CrocodileOP
Yes of course
 export async function createAdvance({ data }: any) {
  const { artistaId: id } = data;
  try {
    const response = await fetch(`${getUrl()}/api/advance/${id}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });

    if (!response.ok) {
      const errorText = await response.text();
      console.error('Failed to create advance:', errorText);
      throw new Error('Failed to create advance');
    }

    const result = await response.json();

    if (result.error) {
      return { error: result.error };
    }
    revalidatePath(`/dashboard/label/gestion-adelantos`);

    return { success: true, response: result };
  } catch (error) {
    console.error('Failed to create advance:', error);
    return { error: error || 'Failed to create advance' };
  }
}


Here is the action where i execute the revalidatePath ( it has the 'use server' in the top of the file )
Avatar
Nile CrocodileOP
more context:
I have the project deployed on vercel
When i commented the deletePath ( under the hood is router.back() ), it works well in local, but still doesnt work in production
Avatar
Pacific sand lance
can u show deletePath and getAdvances functions? also can u show file structure from app/ to gestion-adelantos
Avatar
Nile CrocodileOP
deletePath:
 import { useState } from 'react';

import { useRouter } from 'next/navigation';

export function useDialog() {
  const router = useRouter();

  const [loading, setLoading] = useState(false);
  const [modifyOpen, setModifyOpen] = useState(false);
  const [deleteOpen, setDeleteOpen] = useState(false);

  const deletePath = () => {
    if (loading) return;
    setModifyOpen(false);
    setDeleteOpen(false);
    router.back();
  };

  return {
    loading,
    setLoading,
    modifyOpen,
    setModifyOpen,
    deleteOpen,
    setDeleteOpen,
    deletePath,
  };
}


getAdvances:
 export async function getAdvances() {
  try {
    const response = await fetch(`${getUrl()}/api/advances`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    });

    if (!response.ok) {
      const errorText = await response.text();
      console.error('Failed to get advances:', errorText);
      throw new Error('Failed to get advances');
    }

    const result = await response.json();

    if (result.error) {
      return { error: result.error };
    }

    return { success: true, response: result };
  } catch (error) {
    console.error('Failed to get advances:', error);
    return { error: error || 'Failed to get advances' };
  }
}
Image
i also trying commented deletePath, and it doesn't work neither
Avatar
Nile CrocodileOP
This is the revalidated working in production (I suppose), but the data is not showing
Image