Working with cache on list
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 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 Thank you for looking at this, yes I have:
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