#Why aren't any tags showing up in my tags-manifest.json when using a custom useSwr fetcher

1 messages · Page 1 of 1 (latest)

spiral path
#

I am using a custom useSwr fetcher, which is enabled via the hook, to add the nextConfigOptions into the fetch request.

true glacierBOT
#

Hi @spiral path. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, you can use the useSWR hook for data fetching in Next.js. This hook is part of the SWR library created by the Next.js team and is highly recommended for client-side data fetching. It handles caching, revalidation, focus tracking, refetching on intervals, and more.

Here's an example of how you can use useSWR with a custom fetcher:

import useSWR from 'swr'
 
const fetcher = (...args) => fetch(...args).then((res) => res.json())
 
function Profile() {
 const { data, error } = useSWR('/api/profile-data', fetcher)
 
 if (error) return <div>Failed to load</div>
 if (!data) return <div>Loading...</div>
 
 return (
 <div>
 <h1>{data.name}</h1>
 <p>{data.bio}</p>
 </div>
 )
}

In this example, useSWR is used to fetch profile data. The fetcher function is used to fetch the data and parse the response as JSON. If there's an error during the fetch, it returns a "Failed to load" message. If the data is not yet available, it returns a "Loading..." message. Once the data is available, it displays the user's name and bio.

However, the extracts do not provide information on how to add nextConfigOptions into the fetch request using useSWR. For more detailed usage and configuration options, you may want to check out the SWR documentation (https://swr.vercel.app/docs/getting-started).

Source: Next.js Documentation (https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side)

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@spiral path kapa.ai is still learning and improving, please let us know how it did by reacting below

spiral path
#

@true glacier This issue is mainly happening when I'm using the scoped mutator provided by the useSwr hook, when I mutate the data, it only appears for the time being, but once I refresh the page, the data disappears, because it's being overrided by the fetch cache, which I am unable to purge using the revalidateTags function, because the tags are not registering in the tags-manifest.json file in the .next/cache/fetch-cache folder.

true glacierBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, it seems like you're experiencing an issue with data persistence when using the useSWR hook for data fetching and mutation in Next.js. When you mutate the data, it only appears temporarily and disappears after a page refresh due to the fetch cache.

However, the extracts do not provide specific information on how to handle this issue, particularly with regards to purging the fetch cache using the revalidateTags function or dealing with the tags-manifest.json file in the .next/cache/fetch-cache folder.

The useSWR hook does provide caching and revalidation features, but the specifics of how to manage or purge the cache, or how to handle issues with tags not registering in the tags-manifest.json file, are not covered in the provided extracts.

For more detailed information on how to handle these issues, you may want to refer to the SWR documentation (https://swr.vercel.app/docs/getting-started) or the Next.js documentation (https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@spiral path kapa.ai is still learning and improving, please let us know how it did by reacting below

spiral path
#

@true glacier Why would my fetch call (with provided tags argument) not register in the tags-manifest.json file in the .next/cache/fetch-cache folder? By not register, I mean that the tags provided to the fetch argument are supposed to be apart of the json object stored in the file tags-manifest.json, but they aren't.

true glacierBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, the tags option in the fetch function is used to set the cache tags of a resource. This allows data to be revalidated on-demand using the revalidateTag function. Here's an example of how to use it:

fetch(`<https://...`,> { next: { tags: ['collection'] } })

However, the extracts do not provide specific information on why the tags provided in the fetch function would not register in the tags-manifest.json file in the .next/cache/fetch-cache folder.

There could be several reasons for this issue:

  1. There might be an error in the way the fetch function is being called, or in the way the tags option is being used.
  2. There might be an issue with the Next.js caching mechanism itself.
  3. The tags-manifest.json file might not be updating correctly due to some other issue.

Without more specific information or a detailed error message, it's difficult to determine the exact cause of the issue.

For more detailed information on how to use the fetch function and the tags option, you may want to refer to the Next.js documentation (https://nextjs.org/docs/app/api-reference/functions/fetch). If you continue to experience issues, you might want to consider reaching out to the Next.js community or support for more specific assistance.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@spiral path kapa.ai is still learning and improving, please let us know how it did by reacting below