Skip to content

fix(actions): scope scheduled actions to locale (#222) - #230

Open
nogumaruo wants to merge 1 commit into
pluginpal:masterfrom
nogumaruo:fix/222-locale-aware-actions
Open

fix(actions): scope scheduled actions to locale (#222)#230
nogumaruo wants to merge 1 commit into
pluginpal:masterfrom
nogumaruo:fix/222-locale-aware-actions

Conversation

@nogumaruo

Copy link
Copy Markdown

Summary

Fixes #222 — scheduled publish/unpublish actions were shared across all locales of the same document.

I am opening this on behalf of my teammate @shoh7767, who filed #222 and did the root cause analysis. We have been running this fix in production via patch-package since May, so the approach is battle-tested on our side. @shoh7767 is not able to submit the PR himself right now, so I am contributing it in his place — the analysis and the proposed design are his, and he is credited as co-author on the commit.

What changes

Following the checklist from @TMSchipper's review comment on #222:

  • add locale as an optional field on publisher actionsserver/content-types/action-content-type/index.js
  • preserve Strapi's default query validation when overriding the action find — the override still goes through this.sanitizeQuery(ctx) and this.sanitizeOutput(...), and delegates to the existing action service
  • safely restore filters.locale after sanitizeQuery — Strapi v5 treats locale as a system level i18n parameter and strips it from attribute filters, so the default controller silently ignored it. The override only touches filters.locale when the client actually sent one, and guards against query string serializers that turn null into the literal string 'null'
  • pass locale from the admin UI into getAction()admin/src/components/Action/Action.tsx
  • include locale in the React Query cache key and relevant invalidation pathsadmin/src/hooks/usePublisher.tsx (the getAction query key plus the create/update onSuccess invalidation keys)
  • verify that non-localized publish/unpublish scheduling still works as beforelocale is optional on the schema, and when the admin UI does not supply one, buildQueryKey filters it out and no filters.locale is applied, so the query is byte-for-byte the same as before this change

Upgrade note for maintainers

Actions created before this change have locale = null. On a localized content type, the admin UI will now query filters[locale]=<locale> and will therefore not find those pre-existing rows, so the panel will look empty even though a cron job is still scheduled. The action still executes correctly — only the UI display is affected. If you would like, I can add a fallback that also matches locale: null rows, or a note in the README; let me know which you prefer.

Testing

  • Verified in a Strapi v5 project with i18n enabled: setting a timer on ja no longer shows on en, and both locales can hold independent timers.
  • Verified that a content type without i18n behaves exactly as before.
  • Running in our production environment (Strapi 5.38, Node 24, PostgreSQL) as a patch-package patch.

Happy to adjust naming, comments, or structure to match your preferences.

Scheduled publish/unpublish actions were shared across all locales of the
same document: setting a timer on one locale made it appear on every other
locale, and made independent per-locale scheduling impossible.

Three things were needed:

- add an optional `locale` attribute to the action content type, so the
  locale an action belongs to can be persisted
- override `find` in the action controller to restore `filters.locale`
  after `sanitizeQuery`. Strapi v5 treats `locale` as a system level i18n
  parameter and strips it from attribute filters, so the default controller
  silently ignored the filter. Default query validation is preserved by
  still going through `sanitizeQuery`
- pass `locale` from the admin UI into `getAction()` and include it in the
  React Query cache key and in the create/update invalidation keys, so
  locales no longer share a cached result

Non-localized content types are unaffected: `locale` is optional, and when
the admin UI does not provide one no locale filter is applied.

Fixes pluginpal#222

Co-authored-by: shoh7767 <shoh7767@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

Scheduled actions are shared across locales — locale-aware filtering is needed

1 participant