uppy/examples/react
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
..
src Merge branch 'main' of https://github.com/transloadit/uppy into 5.0 2025-08-20 16:17:08 +05:30
test @uppy/components: fix dropzone global id (#5967) 2025-09-17 10:39:57 +02:00
.stackblitzrc Optmize Stackblitz install times (#5968) 2025-09-16 16:04:52 +02:00
index.html Headless components (#5727) 2025-05-22 09:59:43 +02:00
package.json build(deps-dev): bump vite from 7.0.6 to 7.0.7 (#5962) 2025-09-10 15:30:59 +02:00
tsconfig.json Migrate from Eslint/Prettier/Stylelint to Biome (#5794) 2025-07-01 14:55:41 +02:00
tsconfig.node.json Headless components (#5727) 2025-05-22 09:59:43 +02:00
vite.config.ts Migrate from Eslint/Prettier/Stylelint to Biome (#5794) 2025-07-01 14:55:41 +02:00
vitest.config.ts Migrate from Cypress to Vitest Browser Mode (#5828) 2025-07-28 11:27:37 +02:00