payload icon indicating copy to clipboard operation
payload copied to clipboard

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

Open robinscholz opened this issue 1 year ago • 41 comments

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: https://github.com/payloadcms/payload/blob/b965db881e415cb5bb4a866351c15019ed604b6a/packages/ui/src/providers/UploadHandlers/index.tsx#L44

The function is called here: https://github.com/payloadcms/payload/blob/b965db881e415cb5bb4a866351c15019ed604b6a/packages/plugin-cloud-storage/src/client/createClientUploadHandler.tsx#L39

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

robinscholz avatar Aug 01 '25 13:08 robinscholz

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources

github-actions[bot] avatar Aug 01 '25 13:08 github-actions[bot]

This seems related:

https://stackoverflow.com/questions/79487931/issues-integrating-s3storage-plugin-in-payloadcms

robinscholz avatar Aug 01 '25 14:08 robinscholz

The reproduction can be found here: https://github.com/magicasaservice/payload-plugins-bug I'll happily provide an .env file if needed!

robinscholz avatar Aug 02 '25 12:08 robinscholz

Another related bug it seems: https://github.com/payloadcms/payload/issues/11991

robinscholz avatar Aug 02 '25 13:08 robinscholz

Another one: https://github.com/payloadcms/payload/issues/11717

robinscholz avatar Aug 02 '25 14:08 robinscholz

We have now figured out that running pnpm store prune temporarily solves this issue every time it reoccurs. I’d still be interested to know what’s causing it. If it can’t be fixed, maybe the error message could at least be a more descriptive.

robinscholz avatar Aug 05 '25 06:08 robinscholz

@robinscholz This is a depdendency issue. If you're using pnpm you need to public hoist @payloadcms/* inside your .npmrc. There's a bug inside of @payloadcms/plugin-cloud-storage marking @payloadcms/ui as depdendency rather than peer dependency. Hence duplicate node_modules.

See the following screenshot for the issue:

Image

@jmikrut Not sure who to tag here, 3.50.0 is currently unusable with cloud storage plugin enabled (npm & bun) - pnpm works as its resolution logic correctly hoists @payloadcms/ui

sannajammeh avatar Aug 05 '25 22:08 sannajammeh

anyone else running into this issue, I had to add this to my root package.json

"packageManager": "[email protected]", "pnpm": { "overrides": { "@payloadcms/ui": "3.51.0" } },

and ensure all @payload/* were matching 3.51.

for me specifically it was the azure storage adapter

brphillis avatar Aug 14 '25 05:08 brphillis

anyone else running into this issue, I had to add this to my root package.json

"packageManager": "[email protected]", "pnpm": { "overrides": { "@payloadcms/ui": "3.51.0" } },

and ensure all @payload/* were matching 3.51.

for me specifically it was the azure storage adapter

Facing the same issue using uploadthing plugin

Shows: Error: useUploadHandlers must be used within UploadHandlersProvider

Ghastly2001 avatar Sep 01 '25 08:09 Ghastly2001

+1

daryldeogracias avatar Sep 09 '25 10:09 daryldeogracias

+1

SamHoque avatar Sep 17 '25 13:09 SamHoque

+1 Faced this issue when trying to update payload from "payload": "^3.25.0" to "payload": "^3.57.0"

FadyBengoufa avatar Sep 29 '25 14:09 FadyBengoufa

I'm still running into this issue as well.

I am using yarn

"@payloadcms/db-postgres": "3.59.0",
"@payloadcms/next": "3.59.0",
"@payloadcms/richtext-lexical": "3.59.0",
"@payloadcms/storage-s3": "3.59.0",
"payload": "3.59.0",

aestrro avatar Oct 07 '25 19:10 aestrro

I've assigned this to myself and will prioritise working on this

paulpopus avatar Oct 08 '25 13:10 paulpopus

Thanks @paulpopus - I just generated afresh (v3.59.1) using npx create-payload-app and it still breaks for me.

aestrro avatar Oct 08 '25 17:10 aestrro

Hi guys, I managed to workaround this bug downgrading to 3.51

Later on I still had to upgrade because I use typedRoutes in my project, and that payload version doesn't support them

The weird thing is how the error never showed up again even when reaching 3.59.1

stefan-garofalo avatar Oct 08 '25 19:10 stefan-garofalo

Nothing wrong with trying, I'll post back my findings.

aestrro avatar Oct 08 '25 20:10 aestrro

So, as @stefan-garofalo mentioned, going back to 3.51.0 worked for me:

> /home/node/app/backend # yarn info --recursive | grep payload


│     ├─ @payloadcms/db-postgres@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/graphql@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/next@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/payload-cloud@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/richtext-lexical@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/storage-s3@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ @payloadcms/ui@npm:3.51.0 → npm:3.51.0 [0cc5f]
│     ├─ payload@npm:3.51.0 → npm:3.51.0 [0cc5f]
├─ @payloadcms/db-postgres@npm:3.51.0
│     ├─ @payloadcms/drizzle@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/drizzle@npm:3.51.0
├─ @payloadcms/email-nodemailer@npm:3.51.0
├─ @payloadcms/graphql@npm:3.51.0
│  │  └─ payload-graphql
├─ @payloadcms/next@npm:3.51.0
│     ├─ @payloadcms/graphql@npm:3.51.0 → npm:3.51.0
│     ├─ @payloadcms/translations@npm:3.51.0 → npm:3.51.0
│     ├─ @payloadcms/ui@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/payload-cloud@npm:3.51.0
│     ├─ @payloadcms/email-nodemailer@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/plugin-cloud-storage@npm:3.51.0
│     ├─ @payloadcms/ui@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/richtext-lexical@npm:3.51.0
│     ├─ @payloadcms/translations@npm:3.51.0 → npm:3.51.0
│     ├─ @payloadcms/ui@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/storage-s3@npm:3.51.0
│     └─ @payloadcms/plugin-cloud-storage@npm:3.51.0 → npm:3.51.0
├─ @payloadcms/translations@npm:3.51.0
├─ @payloadcms/ui@npm:3.51.0
│     ├─ @payloadcms/translations@npm:3.51.0 → npm:3.51.0
├─ payload@npm:3.51.0
│  │  └─ payload
│     ├─ @payloadcms/translations@npm:3.51.0 → npm:3.51.0

aestrro avatar Oct 08 '25 20:10 aestrro

@aestrro

So, as @stefan-garofalo mentioned, going back to 3.51.0 worked for me:

After you got a working build is it also fixed permanently when trying to upgrade back like in my case?

stefan-garofalo avatar Oct 08 '25 21:10 stefan-garofalo

+1

nizar-banna avatar Oct 08 '25 22:10 nizar-banna