Skip to content

[@payloadcms/ui] useUploadHandlers throws an error for seemingly no reason #13353

@robinscholz

Description

@robinscholz

Describe the Bug

We are currently trying to build a plugin for media uploads to different providers from within one collection (mux, s3) and are running into problems with payloads architecture.

The UploadHandlersProvider that is injected into the Layout seems to be not ready when our plugin is called. We have essentially modeled our code exactly like the storage-s3 plugin, but for whatever reason we are running into the same error message:

useUploadHandlers must be used within UploadHandlersProvider

The error stems from here:

export const useUploadHandlers = (): UploadHandlersContext => {

The function is called here:

const { setUploadHandler } = useUploadHandlers()

This seems to be the official function to use for creating the necessary components. At least it is used by all the storage plugins.

Sadly we aren’t to knowledgeable about React 19 and React.use(), but it seems like this might be some sort of running condition where a plugin is initialised and thus the function called before the UploadHandlersProvider is able to provide the necessary context. From what I can gather a <Suspense> component should be present somewhere to deal with React.use() returning null? The error seems somewhat aggressive, given the fact that Payloads architecture should provide the correct structure for this to work seamlessly out of the box.

We’ve been digging for quite some time now, but can’t figure it out. It would be great if someone could either point us in the right direction, or if this really is a bug within payload, take a look and work on fixing this.

Link to the code that reproduces this issue

private repo, happy to invite someone

Reproduction Steps

See above

Which area(s) are affected? (Select all that apply)

plugin: cloud-storage

Environment Info

Binaries:
  Node: 20.18.3
  npm: 10.8.2
  Yarn: 1.22.19
  pnpm: 10.14.0
Relevant Packages:
  payload: 3.49.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions