Skip to content

S3 Image Sizes Not Uploaded When Search Plugin is Listed Before S3 Plugin #15431

Closed

Description

@jhb-dev

Describe the Bug

When using both the @payloadcms/plugin-search and @payloadcms/storage-s3 plugins together, if the search plugin is listed before the S3 storage plugin in the plugins array, image sizes are not correctly uploaded to S3:

2026-01-30.08-47-39.mp4

Root Cause Analysis

The issue appears to be related to hook execution order and how the req object is shared between plugin hooks:

  1. Plugin order determines hook order: Payload processes plugins in array order, so the search plugin's afterChange hook runs before the S3 plugin's afterChange hook.

  2. Search plugin modifies req: In syncDocAsSearchIndex.js (lines 83-92 and 156-167), the search plugin's afterChange hook calls nested Payload operations:

    await payload.create({
      collection: searchSlug,  // 'search' collection
      data: {...},
      req  // <-- passes the same req object
    });
  3. S3 plugin depends on req.file: In getIncomingFiles.js (line 2), the cloud storage plugin reads:

    const file = req.file;
  4. The problem: When the search plugin's hook runs first and calls payload.create or payload.update with the same req object, Payload clears or modifies req.file during the nested operation (since the search collection is not an upload collection). By the time the S3 plugin's hook runs, req.file no longer contains the image size data needed for upload.

Expected Behavior

All configured image sizes should be uploaded to S3 regardless of plugin order in the config.

Actual Behavior

When search plugin is listed before S3 plugin:

  • The original/full-size image is uploaded to S3
  • Image sizes (thumbnail, card, etc.) are NOT uploaded to S3
  • No error is thrown, making this difficult to diagnose

Link to the code that reproduces this issue

https://github.com/jhb-dev/payload-s3-search-hook-order

Reproduction Steps

  1. Clone the reproduction repository and run the development server
  2. Configure the .env file with valid S3 credentials
  3. Navigate to /admin and create a user account
  4. Go to the Media collection and upload an image
  5. Check your S3 bucket - you will see only the original image is uploaded
  6. The thumbnail and card sizes defined in the Media collection are NOT uploaded to S3

(see video above for a reproduction)

Which area(s) are affected?

plugin: cloud-storage

Environment Info

Binaries:
  Node: 24.3.0
  pnpm: 10.28.1

Relevant Packages:
  payload: 3.73.0
  next: 15.4.11
  @payloadcms/db-mongodb: 3.73.0
  @payloadcms/plugin-search: 3.73.0
  @payloadcms/storage-s3: 3.73.0

Operating System:
  Platform: darwin
  Arch: arm64

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jan 30, 2026
  2. added
    plugin: cloud-storage
    and removed
    validate-reproduction
    on Jan 30, 2026
  3. self-assigned this
    on Feb 2, 2026
  4. removed
    status: needs-triage
    on Feb 2, 2026
  5. added a commit that references this issue on Feb 18, 2026
    6af3673
  6. github-actions commented on Feb 18, 2026

    @github-actions
    Contributor

    🚀 This is included in version v3.77.0

  7. github-actions commented on Feb 26, 2026

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  8. locked as resolved and limited conversation to collaborators on Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

created-by: Contributorplugin: cloud-storage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions