Unpublishing a published page does not revalidate
Package containing the bug
next-drupal (NPM package)
Describe the bug
A published page shows fine on front-end. But when we unpublish a page it's not revalidating, and the page keep showing on frontend.
I'm seeing below error in Drupal:
GuzzleHttp\Exception\ClientException: Client error: GET https://example.com/api/revalidate?path=/test-page&secret=test-secret resulted in a 404 Not Found response: {"message":"Failed to revalidate /test-page/: Invalid response 500"} in GuzzleHttp\Exception\RequestException::create() (line 113 of /var/www/drupal-website/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
On frontend I'm using:
"next": "14.0.1",
"next-drupal": "^2.0.0-beta.0",
On Drupal I'm using drupal/next:^2.0@beta
Expected behavior
Unpublishing a published page should revalidate and should not be visible on frontend afterwards.
Steps to reproduce:
- Create a page/article on Drupal and publish it.
- Open published page on frontend.
- Unpublish the page from Drupal. It should invalidate the page on frontend.
- Open the same link again on frontend and it shouldn't show anymore.
Additional context
I was earlier using "next-drupal": "^1.60" but it stopped revalidating pages, show previews etc.
I'm now trying "next-drupal": "^2.0.0-beta.0" and so far following test cases are working fine with it:
- showing previews of published/unpublished pages in Drupal.
- creating new pages shows fine on frontend.
- revalidation of published pages.
- revalidation of unpublished pages works fine when checking preview in Drupal but not on frontend.
Hey, did you manage to make revalidation work ? I'm trying to test the Nextjs revalidatePath function but it does not seem to be working. Could you briefly tell me how's your setup ?
Hi @MontiMarco92
With "next-drupal": "^2.0.0-beta.0":
- CMS preview is working for both published and unpublished pages.
- Updating a published page shows updated content on both CMS preview and Next.js frontend.
- But unpublishing a published page does not revalidate as the page keep showing on Next.js frontend.
As I mentioned, on frontend I'm using:
"next": "14.0.1",
"next-drupal": "^2.0.0-beta.0"
And on Drupal: drupal/next:^2.0@beta
Below is the content for pages/api/revalidate.ts
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
request: NextApiRequest,
response: NextApiResponse
) {
let path = request.query.path as string
const secret = request.query.secret as string
// Validate secret.
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) {
return response.status(401).json({ message: "Invalid secret." })
}
// Validate path.
if (!path) {
return response.status(400).json({ message: "Invalid path." })
}
try {
await response.revalidate(path)
return response.json({})
} catch (error) {
return response.status(404).json({
message: error.message,
})
}
}
To revalidate any page we can make a GET request to https://example.com/api/revalidate?path=/test-page&secret={{drupalRevalidateSecret}}
Please let me know if you need any help.
ahh I see.. but you're still working with the pages router, right ? I'm trying to use the App router, hence the usage of the new revalidatePath function, and it's not working for me at the moment.
But thanks for answering!
Yes, I'm still using the pages router. Sorry I have no idea how it works in the app router. Good luck!
Hey @MontiMarco92 Have you implemented the "preview" mode? Take a look at #496. Maybe that's your missing piece :)
Thanks @blyme for your suggestion! I've made it work!