Not sure if anyone else is getting the same issue, but when I run this basic function, the File picker opens the selected file, then opens the file picker again.
If I close the second instance, then run the function again, it runs as expected and opens a selected file.
Are you running that from an sp-button? I had the same issue with the folder picker running from sp-buttons. The event listener semmed to run in an infinite loop. Switching to a native HTML button fixed it. I posted about this a few months ago and other had the same problem too.
Since that time, I implemented a fix for the space and enter key focus issue. I then tried this with sp-buttons again for the folder picker and it also solved the folder picker issue too. I think the button was triggering again when the user clicked to select a folder which is why the folder picker kept opening again. The ânofocusâ fixed Kerri Shots gave me in this post fixed the issue.