Skip to content

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

@Jurdio

Description

@Jurdio

Bug description

autoGenerate: true does not regenerate the sitemap when a document is published or unpublished in Strapi 5.

The autoGenerateMiddleware in the sitemap addon only watches ["create", "update", "delete"]. In Strapi 5, publish and unpublish are separate document service actions and do not go through update, so they are silently skipped and the sitemap is never regenerated.

The sitemap only updates on the next cron tick — not immediately after publishing.

Steps to reproduce

  1. Configure autoGenerate: true in config/plugins.ts
  2. Create a new article (saved as draft)
  3. Publish the article
  4. Immediately check /api/sitemap/index.xml — the article is not present
  5. Wait for the next cron run — the article appears correctly

Root cause

In packages/addons/sitemap/server/src/middlewares/auto-generate.ts:

if (!["create", "update", "delete"].includes(action)) {
  return next(); // publish and unpublish fall through here and are ignored
}

In Strapi 5, publish and unpublish are first-class document service actions (not aliases for update), so they never reach the sitemap generation logic.

Expected behaviour

Sitemap regenerates immediately after a document is published or unpublished, without waiting for the next cron tick.

Fix

Add "publish" and "unpublish" to the action allowlist:

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

Environment

  • webtools-addon-sitemap: 1.3.1
  • strapi-plugin-webtools: 1.10.0
  • Strapi: 5.x

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions