BuidlGuidl / grants.buidlguidl.com

https://grants-bg.vercel.app
MIT License
3 stars 3 forks source link

Fix/cache prod #60

Closed technophile-04 closed 8 months ago

technophile-04 commented 8 months ago

Issue:

NOTE: This only occurs in prod, since there next does caching and build static stuff their.

Demo of admin page not refetching after mutation https://github.com/BuidlGuidl/grants.buidlguidl.com/assets/80153681/2eb751a3-ffb1-4e2b-80fb-77abec506bd5

As we can once I make approve action, things are remaining as it is and not refetching the data.

Reason for above cause:

GET /api/grants/review route handler was static.

NextJS marking api/grants/review as static during build time ![Screenshot 2024-03-03 at 3 43 14 PM](https://github.com/BuidlGuidl/grants.buidlguidl.com/assets/80153681/f7dfc56f-4019-45ae-a082-187a2ff86d96)

Solution:

We need to opt out of caching for GET /api/grants/review route handler.Since we want admin to see updated data as soon as he does mutation.

The way we OPT out of caching for GET is checkout this in docs.

Hence in a4d0c400cc97b369278f87fd19b1e2cf7284749b we make use of request (which makes GET handler as dynamic) and it also reavalidatePath /admin(which was also static). The example was taken from here in docs

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
grants-bg ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 6, 2024 9:41am
carletex commented 8 months ago

Thanks for this Shiv! This is forcing me to learn a bunch about NextJS caching, which is not simple :D

I left a couple of comments.


Sad that this only works for "fetch". With fetch, it shows HIT / MISS on the dev console so there is no need to build & start.

https://nextjs.org/docs/app/api-reference/next-config-js/logging

technophile-04 commented 8 months ago

Tysm, updated 🙌

This is forcing me to learn a bunch about NextJS caching, which is not simple :D

Yeah lol it's not all straightforward :( and docs seem to be kind of distributed too, also the thing it works differently in the dev environment as compared to prod is bad :(

Sad that this only works for "fetch". With fetch, it shows HIT / MISS on the dev console so there is no need to build & start.

Yeah :(