Next.js Discord

Discord Forum

Local cache

Unanswered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Avatar
Golden northern bumble beeOP
If I fetch some data in a layout, I don't see an obvious way to not fetch it again when another segment (which shares that layout) fetches the same thing.

I can cache it on the server - is that what is expected to be done here (still fetching it though)? Or is this bad practice overall (meaning I should not run into this scenario)?

Example:

- In the /item/[id] layout I fetch data for the item with the matching id so we can display the name and some of the other "metadata" as part of the shared layout ui.

- Imagine there is a link that goes to /item/[id]/edit which is part of the same layout. How do I access the data we fetched in the layout on this page without it re-fetching? Since the data already exists in the browser, it makes sense to me that I should be able to instantly get it and not require a refetch, unless I revalidate or mark it in someway to always fetch, right?). My loading ui displays because of this when its just performing the same fetch as the layout just did before navigating to the edit segment.

- Maybe the issue is my data is not granular enough? But what happens when I need any data from the layout regardless (like the metadata for whatever the purpose may be).

Does this make sense?

0 Replies