Next.js 13 revalidatePath with API Route Handlers

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024
  • Learn how to update data on a screen with the revalidatePath function in API Route Handlers.
    NextChat: nextchat.ai
    Other Videos:
    Next.js 13 Server Actions: • Next.js 13 Server Acti...
    Master ChatGPT Prompt Engineering: • Master ChatGPT Prompt ...
    NextChat.ai just killed ChatGPT: • NextChat.ai just kille...
    #nextjs13 #revalidation

ความคิดเห็น • 23

  • @mahmudulmr19
    @mahmudulmr19 ปีที่แล้ว +2

    Thank you so much for this amazing video! I was struggling with a similar issue, and your explanation of revalidatePath with API Route Handlers in Next.js 13 was incredibly helpful. My problem is now solved, and I have a better understanding of how to handle data fetching in my Next.js projects. Keep up the great work!

    • @clickadelic7681
      @clickadelic7681 3 หลายเดือนก่อน

      I totally agree - awesome.

  • @gopallohar5534
    @gopallohar5534 4 หลายเดือนก่อน

    Edit: in app router
    revalidatePath is used when you want to regenerate a chached server component may be because you added a row in database or something
    To make api route dynamic, you use
    ```export const dynamic = 'force-dynamic'```

  • @tmoumimahmoud6966
    @tmoumimahmoud6966 6 หลายเดือนก่อน +1

    thank you , But what if I want only to revalidatePath only after 5 min or 5 hours ? is that possible in the official docs I can't find somthing like this?

    • @ahsanzizan
      @ahsanzizan 5 หลายเดือนก่อน

      You can export a revalidate constant and set it to a certain time (in seconds) in your page.tsx

  • @liu-river
    @liu-river ปีที่แล้ว +1

    Is server action with revalidation the only way to see live update on pages after some CRUD operation without having to refresh the browser? When using server components.

  • @zhacks_admin
    @zhacks_admin ปีที่แล้ว

    I guess it's because you're using a client component.
    I believe cacheing only works in fetch requests done inside of server components.

  • @loverman210
    @loverman210 10 หลายเดือนก่อน

    Does this work across multiple browser tabs? I mean if the revalidated response busts the cache for all tabs.

  • @kingsleykelechionwuchekwa7508
    @kingsleykelechionwuchekwa7508 ปีที่แล้ว

    But this makes the cache Miss. You lose caching totally because the revalidate value gets ignored 😢

  • @phenom2586
    @phenom2586 ปีที่แล้ว

    After following this video, I am still unable to make my homepage update automatically after adding, updating, or deleting data. While everything functions correctly on my local machine, the homepage data does not update when I deploy it to Vercel.

    • @NativeNotify
      @NativeNotify  ปีที่แล้ว

      Try putting "export const revalidate = 0;" at the bottom of your home page file to see if that fixes it

  • @omarkraidie
    @omarkraidie ปีที่แล้ว

    All I want is to revalidate the GET on my homepage when I add a collection from my data base. I tried to add revalidatePath and revalidateTags into both the GET and the PUT route handlers nothing seems to happen. In addition, i event set { cache: 'no-store' } on the get on my homepage still doesnt update my homepage when I make a PUT request then programatically go to homepage with router.push("/")

    • @fr4s0r
      @fr4s0r ปีที่แล้ว +4

      Yeah this is a huge issue I've run into and has resulted in just using client components everywhere with react-query to keep the data in sync.
      That being said, I've just discovered that using revalidatePath in a server action and setting the path to the "homepage" (in your example) results in the page refreshing when navigating back to it.
      Edit: I spoke too soon. It does work when you navigate using router.push and Link but using the browser back button does not refresh it.

    • @iangithinji1452
      @iangithinji1452 6 หลายเดือนก่อน +1

      Its a bit late to ask but did you get a solution to this problem?

  • @rarloscoman
    @rarloscoman ปีที่แล้ว

    getting this log in prod: Failed to revalidate tag Error: Request failed with status 400.

    • @NativeNotify
      @NativeNotify  ปีที่แล้ว

      I sometimes get an error like this about having no revalidate tag in development and have to refresh the page or restart the server over and over again until it works. But then in production it works without an issue.
      I hope that helps

  • @furo.v
    @furo.v ปีที่แล้ว

    This doesn't work so well for server actions. If you have a list of products, and the server action adds one product, and then you execute revalidatePath within the action, the page will be updated with the new data, but there's no way to know when the page is updated, therefore there's no way to show a loading message or spinner during the time the new data is being streamed to the client.
    The documentation recommends wrapping the action call with mutations using the useTransition hook, but this does absolutely nothing, and could be omitted. The isPending from the transition isn't useful either to determine when the data was loaded and when it's being streamed.
    EDIT: Actually startTransition does wait for it, I odn't know anymore lol

    • @codinginflow
      @codinginflow ปีที่แล้ว

      isPending stays true until the revalidation has finished. Sometimes it doesn't seem to work tho (maybe because server actions are still in alpha)

  • @oviemenaokpowodu926
    @oviemenaokpowodu926 ปีที่แล้ว

    I did all this,yet my homepage doesn't revalidate.

    • @NativeNotify
      @NativeNotify  ปีที่แล้ว

      You could try this one: th-cam.com/video/ztswJg7MYCs/w-d-xo.html

  • @peroforrr7663
    @peroforrr7663 ปีที่แล้ว

    Nextchay at the beginning it's free but after you have to pay to use it or you will can't access it forever.
    Euh marketing 😂

  • @kelvindimson
    @kelvindimson ปีที่แล้ว

    Wait… I thought this was the standard