Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomUpload component not used #10281

Open
tylkomat opened this issue Dec 31, 2024 · 3 comments
Open

CustomUpload component not used #10281

tylkomat opened this issue Dec 31, 2024 · 3 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@tylkomat
Copy link

Describe the Bug

A custom Upload component configured in an upload activated collection via admin.components.edit.Upload is not used. Only the default Upload component is used.

The Problem lies here: https://github.com/payloadcms/payload/blob/main/packages/ui/src/elements/BulkUpload/EditForm/index.tsx#L160
The || syntax is not valid for react components, it should be ?:.

Link to the code that reproduces this issue

https://github.com/tylkomat/payload/tree/bug-custom-upload

Reproduction Steps

  1. run `pnpm dev:generate-importmap _community
  2. run pnpm dev _community
  3. visit the Media collection and upload an image to see the Upload component in the edit form

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

area: ui

Environment Info

Payload: 3.12.0
NextJS: 15.1.3
Nodejs: 20.12.2
@tylkomat tylkomat added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 31, 2024
@akhrarovsaid
Copy link
Contributor

Hey @tylkomat,

So this may be related to/possible duplicate of #9591. The root of the issue is that the map of components to override with, currently, does not check for or add a custom upload component. You can add one in config, have the importMap pick it up, but it will not be rendered as it's simply not included in the rendering of fields. There's a PR attached to the aforementioned issue that should do exactly that.

All the || does in the context of rendering React components is check if the first provided value is falsey, and if so, proceed with the second. As custom upload components are not included as of right now, that check will always default to the fallback of the standard Upload element.

Hopefully that PR gets looked at soon though!

@tylkomat
Copy link
Author

Yes, it is a duplicate. Sorry, didn't see the other issue.

@rilrom
Copy link
Contributor

rilrom commented Dec 31, 2024

In the interim I have been using the below @payloadcms/next@^3.12.0 patch to allow the use of a CustomUpload component until the PR is merged in.

diff --git a/dist/views/Document/renderDocumentSlots.js b/dist/views/Document/renderDocumentSlots.js
index a251f39546dcfb9fc566c3d7b948bc80c66a8e00..9d2ba95113ce2579ce998954f92524355e483c8c 100644
--- a/dist/views/Document/renderDocumentSlots.js
+++ b/dist/views/Document/renderDocumentSlots.js
@@ -71,6 +71,13 @@ export const renderDocumentSlots = args => {
       }
     }
   }
+  if (collectionConfig.upload && collectionConfig?.admin?.components?.edit?.Upload) {
+    components.Upload = RenderServerComponent({
+      Component: collectionConfig?.admin?.components?.edit?.Upload,
+      importMap: req.payload.importMap,
+      serverProps
+    })
+  }
   return components;
 };
 export const renderDocumentSlotsHandler = async args => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants