-
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
[NEXT-1186] revalidatePath not working for dynamic routes while res.revalidate works fine #49387
Comments
@roxizhauk from your reproduction steps it seems you are not calling Related response here #49778 (comment) |
Note: we are investigating this behavior more and will add updates here |
There's no way to trigger a revalidation of a specific dynamic route? |
At the moment |
Hi, I ended up here while looking for a way to provoke hard navigate:
So I changed the Is this what you tried to achieve @roxizhauk? All those |
@eric-burel I just quickly built a simple mock with your routing and timing function that I used for my repo but it properly changes the time both on layout and pages. It's weird that your layout isn't updated even with |
Same issue with revalidate path. The path I'm trying to revalidate is like ==> [ws]/blogs/[id]. Also, if I use GET for revalidate I get 405 and If I use POST, it won't be any error. However, in your docs, you suggest using GET for on-demand re-validation. |
@ijjk Hi, is the revalidatePath function designed to be revalidating an individual path or the route? |
We are experiencing the same issue. Using the examples above: App Router
Pages Router
|
Same problem here. Event though the revalidation is not working for |
How should I revalidation from the url if my entire site's route is dynamic? I also have a middleware, as I have different domain names, like domain.it and domain.fr etc. My code:
|
@levipadre The way I handled this was with a tag in the fetch with the slug of the page. With your fetch tagged, you can pass that as the I worked with another dev on the project to discover this, so if you're interested in why it works this way: Firstly, it's worth noting that Next is caching your fetch responses on the filesystem inside Checking this manifest, you'll see that it's not actually caching against the slugs of your pages, but against the filesystem path (the one with dynamic segements in it). As an example, here's an excerpt from mine:
Calling revalidate against a specific slug (like You can see there are various keys under a dynamic segment route, and these relate to how many slugs have been hit for that route. E.g. my first key is for I could revalidate |
Thank you for the explanation @sdjnes. I did check the manifest in fetch-cache and I saw two tags: So yes, I assume it revalidated all pages in this case. I have a few thousand pages generated, so obviously, I don't want to revalidate all of them. The only thig that I don't understand, that if I add a tag to my fetch, like this:
and I call What I would like to do is to revalidate only one page. There is a headless CMS, and all the data comes from a restAPI. When an editor modifies a page (e.g. https://domain.com or https://domain.com/foo or https://domain.com/foo/bar etc.), I would like to update the content on this page. Is there any way to do that? Maybe dynamically add tags to all pages based on their path? |
You can use the slug as the tag. This is how ours looks:
The edge-case for the homepage is because calling Then, in our CMS, we have an onUpdate hook that calls the frontend with the slug of the page (with the logic to handle the homepage edge case) -- something like |
Wow, thank you so much @sdjnes . You are a lifesaver! It works like a charm. You have already helped a lot, but if you don't mind, I would like to ask one more thing. Also cache related, and it seems you know your way around this topic. My menu is acting weird cache-wise. The menu also generated by json and however I added a tag to it, it just doesn't want to cache it. Whenever I change the menu data, it refreshes immediately. The menu is in a header, which is a client component. My code look like this:
the header
and I just import to the layout. Can I cache the same way as the posts? |
@levipadre - the above is related to this issue. If you need help with something else there are loads of other places to do so. This issue's comments should be kept on topic to avoid confusion and therefore extra effort for the maintainers. |
Yes, it's true, I understand. I took a shot. Thanks anyway |
Doing some further testing, I noticed an issue. I don't know if it's only my code or generic, but when I revalidate
and
...so I assume because of the common |
Could you share your code @jwalcher? Just to compare |
|
I'm using 13.4.19 and revalidate path doesn't work for nested routes however my revalidate route handler return 200. @leerob is this api stable? Thanks |
What I currently understand (though it's merely a re-phrase of #49387 (comment)) is:
So I guess we just use them separately for now until they deprecate |
Hi, the An example of the issue that was fixed here, when you only want to revalidate |
Thank you! I confirm that now both updating the cache of one page and updating the cache of the entire route works, using the second argument "page". I just suggest adding to the documentation a variation using routing groups. If you need to clear the entire route segment - revalidatePath("/(main)/post/[slug]","page"). This is not very obvious, given that to clear one page you need to set evalidatePath("/post/post1). I'm really glad this problem is finally fixed. It would also be great if you could help bring the developers' attention to another cache-related issue that has been active for over 6 months. If the page has dynamic parameters, the 404 error is returned only the first time the page is rendered in production. All the following responses return a 200 response. #43831 #48342 #51021 #45801 |
@DennieMello thanks for the flag, opened #55542 and #55543 addressing those. |
This ensures we properly set/restore the status code with ISR paths in app router so that when we set the 404 status code with `notFound` it is persisted properly. Fixes: #43831 Closes: #48342 x-ref: #49387 (comment)
Adds explicit examples for route groups as those may not be obvious from existing examples. x-ref: #49387 (comment)
Thanks @ijjk! Now trying to update from 13.3.0 to 13.5.1, two comments:
I'll keep trying, does either of these sound worthy of a bug report? |
For point 2, there are these issues related to |
Looks related indeed. Funny thing over here is that if I first build in an old version (say 13.4.12), upgrade to 13.3.13 and then build again, there's no error. It only appears after I delete Update: Most closely related issue to second point is #53695, not directly related to revalidation Update: Indeed, issue 2 can be fixed by other means. I'm still curious about 1 though, when exactly revalidation is supposed to happen. |
Thank you for fixing the error so quickly! When using |
@ijjk Dynamic routes visited through |
The problem is still here. But in a smaller effect. I've been testing But when I tried to
it worked only when I was refreshing and staying on the exact same page. Coming from the other page or switching to other page made the cache stale and I could not revalidate anymore. So I had to rebuild the whole project. The bad thing that it's hard to figure out visiting which page makes the cache impossible to revalidate. I can revalidate the page just putting the url in the browser. It works many times in a row. But when I start to go between the pages, at some point revalidation stops working. I am using |
This issue still persists |
same here, revalidatePath() for dynamic routes not working using "next": "13.5.4" |
Experiencing the same issue as well. Using version: |
Same here. Any Using version: |
Found the issue in my code @khristovv. My UI was not updating correctly, however if I logged on the server whatever is returned from the serverAction, it was updating correctly. Try to log the returned value from your API and see if it changes correctly, if it does then revalidatePath() is working well, the issue might be somewhere else. I am using a dynamic route /dashboard/properties/[id] 1 - Getting the
2- passing the details from server component to -> client component and calling the 3- The UI now is updating correctly as long as I only use the data coming directly from the Scrap my old comment, seems to be working correctly, my mistake was assigning the propertyDetails to a new variable in the client component, try to use the return value directly |
Hello, Getting the same problem as people above. I have a simple page in export default () => {
return (
<div>Hello {Date()}</div>
);
} Then I have app revalidate route in import {revalidatePath} from "next/cache";
export async function GET() {
revalidatePath('/static-page', "page");
return Response.json({ revalidated: true })
} And I have pages revalidate route in import { NextApiHandler } from "next";
const handler: NextApiHandler = async (req, res) => {
try {
await res.revalidate('/static-page');
return res.json({ revalidated: true });
} catch (err) {
return res.status(500).send("Error revalidating");
}
};
export default handler; Then I run with Then if I call app revalidate route, the static page does not change, but if I call pages revalidate route, it does change. |
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. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/roxizhauk/revalidate-path
CodeSandBox
To Reproduce
Visit
/blog/[anything]
(e.g./blog/test
) to generate a dynamic page and check the time shownTo try "unsuccessful" app directory's
revalidatePath
:/api/revalidate-path?path=/blog/[anything]
and you'll see "revalidated"/blog/[anything]
and you'll see the time not changedTo try "successful" pages directory's
res.revalidate
:/api/revalidate?path=/blog/[anything]
and you'll see "revalidated"/blog/[anything]
and you'll see the time changedDescribe the Bug
The app directory's
revalidatePath
works fine for "/" or "/blog" but dynamic routes like "/blog/1" or "/blog/test" while pages directory'sres.revalidate
works fine for allExpected Behavior
revalidatePath
works the same asres.revalidate
for dynamic routesWhich browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
From SyncLinear.com | NEXT-1186
The text was updated successfully, but these errors were encountered: