GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

`change` event sometimes never fires on Safari #72

Closed dwelle closed 2 years ago

dwelle commented 2 years ago

Hard to reproduce this one and is may be tied to specific hardware and time (i.e. SSD access speed). I've reproduced on MacOS Safari 14, and iPadOS Safari 14.

Repro case, especially after reload:

https://codesandbox.io/s/reverent-yalow-tk2rp?file=/src/App.js

I can also reproduce on Excalidraw (loading a scene from file).


One way to handle this is to add an interval checking the input.files and resolving if it contains any file:

https://codesandbox.io/s/determined-scott-wfp6o?file=/src/App.js

Strange thing is once this interval is set up it pretty much never reproduces (though it's really hard to disprove a false negative).

Using the setInterval hack would require having an abort handler again. Provided we don't want to do all that here, I propose passing the input into the setupLegacyCleanupAndRejection() (and rename the method to something like legacySetup) so that we can do these hacks ourselves in the host apps.

dwelle commented 2 years ago

Diff: https://github.com/dwelle/browser-fs-access/compare/v0.20.5...main

Works swimmingly on Excalidraw (at least on my machines™): https://github.com/excalidraw/excalidraw/pull/4032

Lemme know and I'll open a PR.

tomayac commented 2 years ago

Fixed via #74.