payloadcms / payloadcms/payload
beforeDuplicate hook iterates locales but does not pass current locale to hook
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
The beforeDuplicate implementation iterates all locales here and passes the value to the defined hooks:
However, the locale value never gets passed to the hook. For instance the following hook gets the wrong locale (always the same value):
hooks: {
beforeDuplicate: [
({ value, req: { locale } }: FieldHookArgs<Page>) => createDuplicateTitle(value, locale)
]
}
The solution would be to pass a different req.locale value:
const beforeDuplicateArgs: FieldHookArgs = {
blockData,
collection,
context,
data: doc as Partial<T>,
field,
global: undefined!,
indexPath: indexPathSegments,
path: pathSegments,
previousSiblingDoc: siblingDoc,
previousValue: siblingDoc[field.name!]?.[locale],
req: {
...req,
locale
},
schemaPath: schemaPathSegments,
siblingData: siblingDoc,
siblingDocWithLocales: siblingDoc,
siblingFields: siblingFields!,
value: siblingDoc[field.name!]?.[locale],
}
This would allow us to localize the field's value in the hook.
Link to the code that reproduces this issue
https://github.com/cbratschi/payload
Reproduction Steps
Define beforeDuplicate hook and check req.locale.
Which area(s) are affected?
area: core
Environment Info
Binaries:
Node: 26.3.0
npm: 11.16.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:39:42 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6031
Available memory (MB): 65536
Available CPU cores: 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/payload/src/fields/hooks/beforeDuplicate/promise.ts around line 72, where the implementation iterates locales and constructs the hook arguments. Use the reproduction steps to verify that beforeDuplicate receives the locale currently being processed through req.locale; done means localized field values reach the hook with the matching locale.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, localization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100