Next.js Discord

Discord Forum

Duplicate requests for `generateMetadata`

Unanswered
Florida White posted this in #help-forum
Open in Discord
Florida WhiteOP
Did someone come up with a solution for this problem: https://stackoverflow.com/questions/76544280/set-metadata-dynamically-without-duplicate-requests-nextjs-13
Answer with caching isn't helpful because the request is already cached by itself. I want to get rid of redundancy in the code.

15 Replies

i don't see your question... cache solves the twice requests...
if it is already cached, then whats the issue
btw cache is the result of the function not anything else (and only per route, so if reloaded twice, only done twice opposed to 4 times)
Florida WhiteOP
cache is returning a callback that you have to await
but you still have to do that twice
i want to do that in one go just like in the old /pages directory
@Florida White but you still have to do that twice
yeah but only the first time your code is run
the await is because it doesn't know the order
and it can possibly not have said cache, so it should be awaited as it may need to run the code again
@Florida White but you still have to do that twice
Since the two functions are run independently, this is how you are supposed to run it
You can come up with weird global singleton or cache() shenanigans to reduce the code to one place, but I don’t recommend that
Florida WhiteOP
ok, does it make any sense to use 'cache' function at all if im using 'force-cache' in my fetch?
@Florida White ok, does it make any sense to use 'cache' function at all if im using 'force-cache' in my fetch?
Didn’t check your SO post, but fetch() are deduped automatically so it doesn’t make much sense to use cache() with it
Florida WhiteOP
it wasnt my post, but i was thinking the same as the guy who created it