uppy/packages/@uppy/components/src
Prakash d6b3aa575e
@uppy/components: fix dropzone global id (#5967)
fixes #5946 

Root Cause : 

`createDropzone` used a single global `id` for the file input
(`'uppy-dropzone-file-input'`) Clicking any `<Dropzone />` did
`document.getElementById(<global-id>).click()`, which always targeted
the first input in the DOM, so files were added to the first Uppy
instance.


9bac4c8398/packages/%40uppy/components/src/hooks/dropzone.ts (L73-L77)


**Solutions :**

Simplest solution would have been to just make the input id unique per
Uppy instance using `ctx.uppy.getID()`, and click that specific input.

```typescript

const fileInputId = 'uppy-dropzone-file-input-' + ctx.uppy.getID()

```
  **Caveats**:
  
If users don’t pass a custom id to `new Uppy()`, all instances default
to uppy, so ids still collide across instances.
  Multiple Dropzones under one instance still share the same id.
  

Switched to a ref-based approach so clicks trigger the input directly,
without relying on `document.getElementById` lookups. It still falls
back to a DOM click for backward compatibility.

**StackBlitz Link :** 


https://stackblitz.com/github/qxprakash/uppy/tree/debug_dropzone/examples/react?file=package.json&embed=1&view=editor&showSidebar=1&hideTerminal=1

  


**Update: Went for the ID based solution upon discussion with the team
as it's simpler.**
2025-09-17 10:39:57 +02:00
..
hooks @uppy/components: fix dropzone global id (#5967) 2025-09-17 10:39:57 +02:00
Dropzone.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
FilesGrid.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
FilesList.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
index.ts Migrate from Eslint/Prettier/Stylelint to Biome (#5794) 2025-07-01 14:55:41 +02:00
input.css Use turbo for building and watching concurrently (#5808) 2025-07-10 13:21:18 +02:00
ProviderIcon.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
Thumbnail.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
types.ts Add useDropzone & useFileInput (#5735) 2025-06-09 10:54:28 +02:00
UploadButton.tsx Run biome check on main (#5896) 2025-08-11 10:06:21 +02:00
uppyEventAdapter.ts Migrate from Eslint/Prettier/Stylelint to Biome (#5794) 2025-07-01 14:55:41 +02:00