You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Click Reload Page button and see the Current time update
Click Revalidate with tag and then reload page - Notice the Cached time from API does not update
Click Revalidate with encoded tag - Notice the page reloads and the Cached time from API is now updated
Current vs. Expected behavior
Current
If a tag contains special characters that is not safe in a url. The cache with the tag wont be revalidated.
This is due to revalidateTag not encoding the tag before appending it to the cache invalidation url.
fixes#61390
### What?
Added encodeURIComponent to encode revalidateTag value beforing
appending it to the url.
### Why?
If a tag contains special characters the tag wont be revalidated because
the special characters arent encoded.
By encoding the tag any special characters can be used.
Check out issue #61390 for further explanation
I believe this is the reason why users report the revalidateTag as
unreliable. They might be using special characters in their tags to make
sure they are unique, but when deployed to vercel and the fetch cache is
used revalidateTag fail to revalidate them.
### How?
By encoding revalidateTag with encodeURIcomponent the tag can contain
special characters.
Closes NEXT-
Fixes#61390
---------
Co-authored-by: JJ Kasper <[email protected]>
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://github.com/OMikkel/nextjs-fetch-cache-tag-revalidation-issue-replication
To Reproduce
Reload Page
button and see the Current time updateRevalidate with tag
and then reload page - Notice the Cached time from API does not updateRevalidate with encoded tag
- Notice the page reloads and the Cached time from API is now updatedCurrent vs. Expected behavior
Current
If a tag contains special characters that is not safe in a url. The cache with the tag wont be revalidated.
This is due to revalidateTag not encoding the tag before appending it to the cache invalidation url.
next.js/packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Line 127 in 292cd0d
If i manually encode the tag like this
revalidateTag(encodeURIComponent(<tag>))
it now works every single time 😃Expected behavior
The tag should revalidate when
revalidateTag(<tag>)
is called no matter what characters the string containsProvide environment information
Which area(s) are affected? (Select all that apply)
App Router, Data fetching (gS(S)P, getInitialProps)
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
I went through all the releases to find the version where
revalidateTag
was introduced.It appears it was introduced in version
v13.3.1-canary.17
and it appears to have the same issue back then. The tags are not encoded before being appended to the cache invalidation url.https://github.com/vercel/next.js/blob/v13.3.1-canary.17/packages/next/src/server/lib/incremental-cache/fetch-cache.ts
I am also using this workaround to use the data cache during vercel build.
https://github.com/evankirkiles/nextjs-broken-data-cache-demo
Issue: vercel/next.js#56370
PR to fix this issue
This pr should fix the issues. #61392
It works in my ecommerce application if i encode tags.
Video of the issue
Temporary fix
The text was updated successfully, but these errors were encountered: