next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

Working with cache on list

Open rpayanm opened this issue 9 months ago • 3 comments

Package

next-drupal (NPM package)

Ask the question

In the app/page.tsx I have this code:

export default async function Home() {
  const nodes = await drupal.getResourceCollection<DrupalNode[]>(
    "node--article",
    {
      params: {
        "filter[status]": 1,
        "fields[node--article]": "title,path,field_image,uid,created,body",
        include: "field_image,uid",
        sort: "-created",
      },
      next: {
        tags: ['node_list:article'],
      },
    }
  )

  return (
    <>
      <h1 className="mb-10 text-6xl font-black">Latest Articles.</h1>
      {nodes?.length ? (
        nodes.map((node) => (
          <div key={node.id}>
            <ArticleTeaser node={node} />
            <hr className="my-20" />
          </div>
        ))
      ) : (
        <p className="py-4">No nodes found</p>
      )}
    </>
  )
}

I am running npm run preview and I expect that if I create, edit, or delete any article in Drupal, the list on the Next.js app will be updated, but it is not.

How do I accomplish that?

rpayanm avatar Mar 15 '25 14:03 rpayanm

@rpayanm Has On-demand Revalidation been implemented? It's required to ensure content updates are reflected on the site.

For more details, see the documentation: https://next-drupal.org/learn/on-demand-revalidation

ksk1kd avatar Mar 24 '25 12:03 ksk1kd

@ksk1kd Thank you for looking at this, yes I have:

Image

Image

Image

rpayanm avatar Jun 03 '25 12:06 rpayanm

I was debugging the code, and the sites variable is empty:

https://git.drupalcode.org/project/next/-/blob/2.x/src/Plugin/Next/Revalidator/CacheTag.php?ref_type=heads#L53

It is later used here to invalidate the cache:

https://git.drupalcode.org/project/next/-/blob/2.x/src/Plugin/Next/Revalidator/CacheTag.php?ref_type=heads#L68

I created a new field in my article content type to assign the my_app site, but it did not work. I could not find where the setSites function is called:

https://git.drupalcode.org/project/next/-/blob/2.x/src/Event/EntityActionEvent.php?ref_type=heads#L112

rpayanm avatar Jun 03 '25 13:06 rpayanm