Skip to content

beforeDuplicate hook iterates locales but does not pass current locale to hook #17021

Description

@cbratschi

Describe the Bug

The beforeDuplicate implementation iterates all locales here and passes the value to the defined hooks:

https://github.com/payloadcms/payload/blob/main/packages/payload/src/fields/hooks/beforeDuplicate/promise.ts#L72

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore Payload functionalitystatus: needs-triagePossible bug which hasn't been reproduced yetv3

    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