-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
Revalidation not working in deployment mode #56231
Comments
I am also getting the same issue and I am using next v13.4.19 . It is literally a headache that I have tried every single solution for that even I have used no-store instead of doing cache. It also stucks. Data fetching is still an issue. Next js team should work on that ASAP as it is disturbing many production sites. |
We have the same issue |
Since this happens to us in a project that is really important, we had to find out a solution -- not the best solution, but it does the job All we did is change the request method to This is the function that fetches data and runs in the server: const getAvailableTasks = async () => {
try {
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}api/tasks`, {
cache: "no-store",
method: "PUT", // change GET to PUT
next: { revalidate: 0 },
});
if (!res.ok) {
throw new Error("Failed to fetch topics");
}
const availableTasks = await res.json();
return availableTasks;
} catch (error) {
console.log("Error loading topics: ", error);
}
}; And this the controller that fetch the data, must be connectDB();
// ? GET all available tasks
export async function PUT(request: NextRequest) {
try {
// TODO : find user county => get tasks for them ...
// const userID = await getDataFromToken(request);
// const user = await User.findOne({_id: userId}).select("-password");
const availableTasks = await Task.find();
return NextResponse.json(availableTasks);
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 400 });
}
} This is our temporary solution until NextJS team fix the bug. |
Wow, please give more details on how to do it, I'm dealing with this issue 3 days now! Where I can fin that? Thanks, MAhmed! |
If you are using turbo then make cache false in turbo.json. And other thing is try purging cache of project in settings of project on vercel. And check docs of cache they recently updated. |
I think it's not Vercel problem, if you try to build locally and run
Finally 😴 |
So will that also work with time based revalidation. Because sometimes its also not gotta work. |
Also seeing @obtusei's exact issue using headless WP, would greatly appreciate updates. I am eventually seeing the in-app updates for both WP post creation and post updates, but they take anywhere from 5 minutes to 30 to actually propagate. Apparently the default WP REST API cache expiry settings can sometimes affect this, but in my case I can see the updates immediately after publishing when I fetch via a client service like Insomnia - so the WP cache seems to not be a factor here. |
fixes: #58909 x-ref: #58321, #56472, #56231 Removed the Math.round of age since it can cause stale fetch data to be considered not stale if the age rounds downwards. (5.49 is rounded to 5) Note: This most likely also fixes some bugs with revalidateTag/revalidatePath. Tested some tag/path issues that got fixed with this change. I think this is because revalidatetag/path sets [data.revalidatedAt = Date.now()](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/incremental-cache/file-system-cache.ts#L120) for file-system-cache. And with the current code that value would continue to be "not stale" for up to 0.499 ms. Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Zack Tanner <zacktanner@gmail.com>
Link to the code that reproduces this issue
https://github.com/obtusei/nextjs-test
To Reproduce
My Code:
Current vs. Expected behavior
Expected Behavior:
Posts to be revalidated every 10 seconds in deployment. If the posts are updated in backend, they should also be updated in nextjs application after 10 seconds.
Observed behavior
The posts are updated in backend, they aren't being updated in nextjs application after 10 seconds. (In Deployment/Production Mode)
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.6.0: Thu Jun 8 23:57:12 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_X86_64 Binaries: Node: 18.16.0 npm: 9.6.5 Yarn: 1.22.19 pnpm: 8.6.5 Relevant Packages: next: 13.5.3 eslint-config-next: 13.5.3 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Data fetching (gS(S)P, getInitialProps)
Additional context
No response
The text was updated successfully, but these errors were encountered: