fix(actions): scope scheduled actions to locale (#222) - #230
Open
nogumaruo wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-packagesince 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:
localeas an optional field on publisher actions —server/content-types/action-content-type/index.jsfind— the override still goes throughthis.sanitizeQuery(ctx)andthis.sanitizeOutput(...), and delegates to the existingactionservicefilters.localeaftersanitizeQuery— Strapi v5 treatslocaleas a system level i18n parameter and strips it from attribute filters, so the default controller silently ignored it. The override only touchesfilters.localewhen the client actually sent one, and guards against query string serializers that turnnullinto the literal string'null'localefrom the admin UI intogetAction()—admin/src/components/Action/Action.tsxlocalein the React Query cache key and relevant invalidation paths —admin/src/hooks/usePublisher.tsx(thegetActionquery key plus the create/updateonSuccessinvalidation keys)localeis optional on the schema, and when the admin UI does not supply one,buildQueryKeyfilters it out and nofilters.localeis applied, so the query is byte-for-byte the same as before this changeUpgrade note for maintainers
Actions created before this change have
locale = null. On a localized content type, the admin UI will now queryfilters[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 matcheslocale: nullrows, or a note in the README; let me know which you prefer.Testing
jano longer shows onen, and both locales can hold independent timers.patch-packagepatch.Happy to adjust naming, comments, or structure to match your preferences.