NextJS revalidate path with supabase
Unanswered
English Spot posted this in #help-forum
English SpotOP
Am i missing something or i did something wrong? So in my explore page there's a profile card that use the user username. and the page only update the value when i refresh the page
And this is my explore page
export async function usernameChange({ username }: usernameChangeSchema) {
// Username Update
revalidatePath('/explore', 'page');
return { data };
}And this is my explore page
export default async function ExplorePage() {
const users = await getCreators();
return(
//Explore Page
)export async function getCreators() {
const supabase = createServerClient();
try {
const { data, error } = await supabase
.from('user_profiles')
.select('*')
if (!data) {
throw error;
}
return data;
} catch (error) {
console.error('Error:', error);
throw error;
}
}25 Replies
I think we have similar problems, no clue what the solution is tho
https://nextjs-forum.com/post/1252442613060210719
https://nextjs-forum.com/post/1252442613060210719
@Iischeese I think we have similar problems, no clue what the solution is tho
https://discord.com/channels/752553802359505017/1252442613060210719
English SpotOP
I just think supabase is not supported with revalidatePath? π
https://supabase.com/blog/fetching-and-caching-supabase-data-in-next-js-server-components
https://supabase.com/blog/fetching-and-caching-supabase-data-in-next-js-server-components
one thing i found is if we use
it will work, but not any other else, but this will revalidate everything which i do not want
revalidatePath('/', 'layout')it will work, but not any other else, but this will revalidate everything which i do not want
I thought that was in the example project?
Strange, still dosnt work for me.
English SpotOP
Which example project can you link it here?
npx create-next-app -e with-supabase
English SpotOP
Hmm idk if it is okay to tag some mod / helper
I actually cant find that they used revalidatePath in the example project
English SpotOP
@joulev
So I am calling the usernameChange function here
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/settings/_components/actions.ts
And the fetch function here, but somehow it is not revalidated and the previous data still cached. When I manually refresh the page then the data got updated / changed.
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/explore/page.tsx
So I am calling the usernameChange function here
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/settings/_components/actions.ts
And the fetch function here, but somehow it is not revalidated and the previous data still cached. When I manually refresh the page then the data got updated / changed.
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/explore/page.tsx
@English Spot <@484037068239142956>
So I am calling the usernameChange function here
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/settings/_components/actions.ts
And the fetch function here, but somehow it is not revalidated and the previous data still cached. When I manually refresh the page then the data got updated / changed.
https://github.com/billgun/kreasea/blob/main/app/(dashboard)/explore/page.tsx
the way i look at it, you are only revalidating
/explore and not /settings? then after revalidation, the /settings page content should still be the same, no?@joulev the way i look at it, you are only revalidating `/explore` and not `/settings`? then after revalidation, the `/settings` page content should still be the same, no?
English SpotOP
Yes, what I want to revalidate is the /explore page
I want to revalidate the /settings page as well but not now.
I want to revalidate the /settings page as well but not now.
@English Spot Yes, what I want to revalidate is the /explore page
I want to revalidate the /settings page as well but not now.
* if you fetch the data in /settings and revalidate /settings as well, does it work (for /settings)?
* if you
* if you
redirect to /explore, does it show the new data?@joulev * if you fetch the data in /settings and revalidate /settings as well, does it work (for /settings)?
* if you `redirect` to /explore, does it show the new data?
English SpotOP
Hey, it seems to be working now
Looks like I need to wrap my function into a try catch function
Looks like I need to wrap my function into a try catch function
Both of the questions above is no, for the questions above before i added the try / catch
π
Looking into this, giving me a try to add try / catch block for my function
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#redirecting
Redirecting
If you would like to redirect the user to a different route after the completion of a Server Action, you can use redirect API. redirect needs to be called outside of the try/catch block:https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#redirecting
redirect needs to be called outside try/catch but revalidatePath needs not be called that way 
English SpotOP
oh okay, that's weird π€
well, if it works it works
English SpotOP
So why does it only works when i put it inside try / catch π
Yeah, thanks!
English SpotOP
Hey @Iischeese you might want to try wrapping your function inside of try/catch