Skip to content

Memory leak when opening a file picker multiple times without selecting a file #105

@MrKampla

Description

@MrKampla

use-file-picker is creating an invisible input element and attaching it to the DOM under the hood. It does that in order to reliably trigger the file picker UI in all browsers (Safari needs this #34). The problem is that in our openFileDialog.ts helper, we're only clearing this input from the DOM on a successful file selection.
If user opens the file selector, and then doesn't select anything, the dom element is gonna stay there indefinately. It is not a huge issue but it should be fixed.

In order to do that, we can add an 'cancel' event listener which I've tested and it works reliably on chrome and safari, both on desktop and mobile. We were trying to implement something like this a few years ago (#58) but it didn't work back then. Now seems like the browser support is ready to implement such feature.

Image

This will also allow us to finally return a promise from the openFilePicker funciton!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions