fix: write per-locale values from siblingData when req.locale is 'all'#16676
Open
rachit367 wants to merge 1 commit into
Open
fix: write per-locale values from siblingData when req.locale is 'all'#16676rachit367 wants to merge 1 commit into
rachit367 wants to merge 1 commit into
Conversation
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.
Fixes #16345.
The beforeChange merge-locale loop in
fields/hooks/beforeChange/promise.tsonly writes a localized field's incoming value whenlocale === req.locale. When the caller passeslocale: 'all', no real locale code ever equals'all', so the incoming value is never written and the field appears not to update — every existing per-locale value is preserved instead.Read-side already treats
locale === 'all'as meaning "the field holds a{ [locale]: value }map" — see e.g. the explicit comment infields/hooks/afterRead/promise.ts(shouldRunHookOnAllLocales). The write side should mirror that: whenreq.locale === 'all',siblingData[field.name]is the same{ [locale]: value }shape and should be merged key-by-key.Change
In the merge action, detect the
'all'case and treatsiblingData[field.name]as a per-locale map:siblingDocWithLocales[field.name][locale]For any other
req.localethe originallocale === req.locale ? ... : ...branch runs unchanged, so single-locale updates behave exactly as before.Cases I traced
req.locale = 'en', payload{ title: 'new' }— unchanged (raw value goes toen, other locales preserved).req.locale = 'all', payload{ title: { en: 'a', es: 'b' } }—enandesupdated, other locales preserved.req.locale = 'all', payload{ title: { en: 'a' } }— onlyenupdated,es/de/... preserved.req.locale = 'all', payload{ title: 'a' }(malformed — not an object) —incomingAllLocalesresolves toundefined, loop hits the original branch where no locale matches'all', so behavior matches today (no-op). No new regression for malformed input.Reporter's repro at https://github.com/MartijnDeRoode/payload-reproductions should produce updates to all three text fields after this change.
I didn't run the integration suite locally — the change is scoped to one merge-action block and the existing behavior is preserved for every code path that wasn't
req.locale === 'all'. Happy to add a targeted test if there's a preferred suite for this path.