next.js
next.js copied to clipboard
How to update current route data by using revalidateTag in the server action??
Link to the code that reproduces this issue
https://github.com/takakikasuga/revalidate-app
To Reproduce
Now, I study app router and the next cahce like data cache and so on... I try to do some option of fetch and revalidate tag and path. today, I use revalidateTag in the server action, and I wanna update data of the tag and I don't expect to update data other than tag.
In this below video, I updated layout tag
in the ActionLayout, but after revalidate layout tag
, other tag data like page tag
in the ActionPage and root tag
int the RootLayout was updated.
I don't know this action happend...
additionally, after updated data related to all tags and reload the browser, layout tag
was updated correctly but, other than tag like page tag
and root tag
wasn't updated and display old cached data...
https://github.com/user-attachments/assets/357a2961-82d1-4e79-913e-c1d6193a1043
How can I update current data by revalidateTag???👀
but,,, there is one thing, I succeeded in the specified tag's data.
I inject redirect function after revalidate tag and redirect to current route, I can found the my expectation that layout tag
was updated and other than tag like page tag
and root tag
wasn't updated like below the video.
but I don't know this implementation is correct because this implementation example don't be writtern in the nextjs official document.
(I refered to the this youtube)
https://github.com/user-attachments/assets/142c9c49-284e-4c42-92cb-b57dae325743
I love the nextjs, thank you for your project and the best effort for software enginner!!
Current vs. Expected behavior
I wanna update data of the tag and I don't expect to update data other than tag by using only revalidateTag, it means I don't use redirect.
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
Available memory (MB): 65536
Available CPU cores: 10
Binaries:
Node: 20.14.0
npm: 10.7.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
next: 14.2.7 // Latest available version is detected (14.2.7).
eslint-config-next: 14.2.7
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
create-next-app
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response