Skip to content
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

Unpublishing a published page does not revalidate #772

Open
maverickdude opened this issue May 30, 2024 · 6 comments
Open

Unpublishing a published page does not revalidate #772

maverickdude opened this issue May 30, 2024 · 6 comments
Labels
bug Something isn't working triage A new issue that needs triage

Comments

@maverickdude
Copy link

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:

  1. Create a page/article on Drupal and publish it.
  2. Open published page on frontend.
  3. Unpublish the page from Drupal. It should invalidate the page on frontend.
  4. 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.
@maverickdude maverickdude added bug Something isn't working triage A new issue that needs triage labels May 30, 2024
@MontiMarco92
Copy link
Contributor

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 ?

@maverickdude
Copy link
Author

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.

@MontiMarco92
Copy link
Contributor

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!

@maverickdude
Copy link
Author

Yes, I'm still using the pages router. Sorry I have no idea how it works in the app router. Good luck!

@blyme
Copy link
Contributor

blyme commented Jun 12, 2024

Hey @MontiMarco92 Have you implemented the "preview" mode? Take a look at #496. Maybe that's your missing piece :)

@MontiMarco92
Copy link
Contributor

Thanks @blyme for your suggestion! I've made it work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage A new issue that needs triage
Projects
None yet
Development

No branches or pull requests

3 participants