-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
revalidate, revalidateTag and revalidatePath not working as intended #49778
Comments
Hi, everything appears to be working properly in the provided reproduction with the latest canary of Next.js as can be seen in the below recording. Something to note from above is that revalidatePath should be called with the page's pathname not the URL e.g. CleanShot.2023-05-14.at.11.18.55.mp4 |
Thank you @ijjk for looking into this, I really appreciate it. I can see that it works perfectly for you. However it doesn't for me as you can see in the screen recording. Each time both update, could this be a windows issue? https://github.com/vercel/next.js/assets/47059262/20cac5e1-c652-4073-b6c8-6fe86de86572 Thank you for clarifying the dynamic revalidatePath, I've seen that a lot of people seem to be unclear on this as, like me, would expect to be able to update a single path, say for example, CMS posts. Having to rebuild everyone isn't ideal, is there someway around this? |
Wouldn't that mean that revalidating a dynamic path would revalidate every dynamic page generated in the cache for that dynamic route? |
Temporary workaround is to add a [slug] tag to the fetch functions in the dynamic path and then call revalidateTag. |
@joncoronel if you want to revalidate a specific pathname e.g. |
@ijjk I found that after the 13.4 update, the old method of On-Demand ISR through res.revalidate no longer works with pages in app dir. I get an error message. Okay got it that makes more sense. So when I visit a dynamic path that was already in cache that has been revalidated through revalidatePath, would it still first show the cached version of the dynamic path and revalidate in the background similar to time-based ISR or would it wait to load the page until it is revalidated like how it would if that dynamic path has not been generated yet/not in cache? |
Is this the intended behavior for |
@ijjk Hi, can you elaborate this more? e.g. After using validatePath('/blog/[slug]'), if i visit /blog/my-post-1, that will get regenerated, then I visit /blog/my-post-2, but that will not get regenerated because my-post-1 has been regenerated? |
Should this be re-opened? It's still an issue as @tutorialcode pointed out |
I wasn't pointing out an issue, i was only asking for more clarification. I'm good now. |
I still have this problem. // app/create-post/actions.ts
export async function createPost(content: string) {
const { userId, orgId } = auth();
await db.insert(posts).values({ content });
revalidatePath("/view-posts");
} // app/view-posts/page.tsx
async function getPosts() {
"use server";
const posts = await db
.select()
.from(postsTable)
return posts;
}
export default async function Posts({
params,
}... I'm trying to create something on one page and revalidate another, but when I click "back" in the browser to get to I've tried putting some console.logs in my code and it looks like the component is rendered before the server action ( Am I using server actions wrong??? Update: Navigating with browser' "forward" and "back" uses its own cache and there is no way to get over this without making it refetch and rerender every time it is shown which involves making it a client component and removes all advantages of having it render on the server. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Data fetching (gS(S)P, getInitialProps)
Link to the code that reproduces this issue
https://github.com/epndavis/nextjs-revalidate-issue
To Reproduce
Go to http://localhost:3000/api/revalidate?tag=graphql
Back to homepage, refresh the page a couple of times to get the new data
Describe the Bug
Steps 1 and 2 refresh all data on the page. There are two fetch requests on the homepage, one with revalidation (GRAPHQL) the other cached indefinitely (API). When revalidated through any of these methods the GRAPHQL is revalidated but the API fetch request is also revalidated.
Step 4. If revalidatePath is used on a dynamic route nothing happens unless revalidateTag is used.
Expected Behavior
We would expect that only the revalidated request is re-run, the cached fetch request should remain static. If revalidating a page it shouldn't revalidate everything unless it is requested to be revalidated as in step 3 via the path. This is as described in this youtube video and recently this tweet
We would also expect dynamic routes to be revalidated via
revalidatePath
.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: