Skip to content

iOS Safari drops photos when the file input is garbage collected #1333

Open

Description

@lylo

On iPhone Safari, photos chosen with the image button are sometimes dropped. The picker closes back to the editor, nothing is inserted, no error shows and no upload starts.

It depends on how long the picker stays open, not on how many photos are picked. Quick picks work, even with 10 photos. After about 10 seconds in the picker, nothing is inserted however many are picked. I saw this in Safari 27.2 on Lexxy 1.0.3.

Steps to reproduce

Waiting makes this intermittent, because it depends on when Safari collects garbage. Forcing a collection from Web Inspector on the Mac makes it repeat every time:

  1. Connect the iPhone and open Safari Web Inspector on a page with an editor
  2. Tap the image button and wait 2 seconds, leaving the picker open
  3. Run console.takeHeapSnapshot() in the console
  4. Pick one photo and tap the tick

Nothing is inserted.

Cause

#dispatchUploadAttachment removes the file input a second after clicking it and keeps no reference to it:

this.editorElement.appendChild(input)
input.click()
setTimeout(() => input.remove(), 1000)

While the picker is open, the input can be garbage collected. In WebKit, a disconnected input's wrapper isn't kept alive (JSNodeOwner::isReachableFromOpaqueRoots), ~FileInputType invalidates the chooser, and FileChooser::chooseFiles then returns without a client. So neither change nor cancel fires.

WebKit hit the same thing in its own Web Inspector and fixed it the same way: "Keep the input element alive so it doesn't get garbage collected, which makes the file chooser do nothing" (bug 201290).

To confirm it, I repeated the steps above with a reference to the input held in window, and the photo was inserted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions