Skip to content

fix(sitemap): trigger autoGenerate on publish and unpublish actions#417

Open
Jurdio wants to merge 2 commits into
pluginpal:masterfrom
Jurdio:fix/auto-generate-publish-unpublish
Open

fix(sitemap): trigger autoGenerate on publish and unpublish actions#417
Jurdio wants to merge 2 commits into
pluginpal:masterfrom
Jurdio:fix/auto-generate-publish-unpublish

Conversation

@Jurdio
Copy link
Copy Markdown

@Jurdio Jurdio commented May 19, 2026

Problem

autoGenerate: true does not regenerate the sitemap when a document is published or unpublished in Strapi 5. The sitemap only updates on the next cron tick.

Closes #416

Root cause

The autoGenerateMiddleware allowlist only includes create, update and delete:

if (!['create', 'update', 'delete'].includes(action)) {
  return next();
}

In Strapi 5, publish and unpublish are separate document service actions — they do not go through update. So publishing a document silently skips the middleware and the sitemap is never regenerated.

Fix

Add publish and unpublish to the allowlist:

if (!['create', 'update', 'delete', 'publish', 'unpublish'].includes(action)) {
  return next();
}

Testing

  1. Enable autoGenerate: true in plugin config with excludeDrafts: true
  2. Create a new entry (saved as draft)
  3. Publish the entry
  4. Check /api/sitemap/index.xml — entry now appears immediately without waiting for cron
  5. Unpublish the entry — entry is removed from sitemap immediately

Related

In Strapi 5, publish and unpublish are separate document service actions
and do not go through the update action. The previous allowlist only
included create, update and delete, so publishing or unpublishing a
document never triggered sitemap regeneration.

Adds publish and unpublish to the allowlist so autoGenerate works
correctly in Strapi 5 draft-and-publish workflows.

Fixes pluginpal#416
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: 75e708b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webtools-addon-sitemap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] autoGenerate does not trigger on publish/unpublish in Strapi 5

1 participant