<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>201289</bug_id>
          
          <creation_ts>2019-08-28 23:56:04 -0700</creation_ts>
          <short_desc>&lt;input type=&quot;file&quot;&gt; is not kept alive during file picker, if it gets GC&apos;d file selection has no affect</short_desc>
          <delta_ts>2019-08-30 09:32:49 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Forms</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=201290</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joseph Pecoraro">joepeck</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>hi</cc>
    
    <cc>joepeck</cc>
    
    <cc>rniwa</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1566123</commentid>
    <comment_count>0</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2019-08-28 23:56:04 -0700</bug_when>
    <thetext>A `&lt;input type=&quot;file&quot;&gt;` can get GC&apos;d while the dialog is up if the element is not in the DOM.

When the Element is GC&apos;d the FileChooser get&apos;s invalidated and the file selection gets dropped on the floor.

Should we try to guarantee the element is kept around while the picker is showing (at least not collected)? Note, Web Content has a workaround, but seems weird.

Test:
```
&lt;button id=&quot;x&quot;&gt;Click&lt;/button&gt;
&lt;script&gt;
document.getElementById(&quot;x&quot;).addEventListener(&quot;click&quot;, () =&gt; {
    let inputElement = document.createElement(&quot;input&quot;);
    inputElement.type = &quot;file&quot;;
    inputElement.multiple = true;
    inputElement.addEventListener(&quot;change&quot;, (event) =&gt; {
        alert(&apos;change&apos;);
    });
    inputElement.click();
});
&lt;/script&gt;
```

Steps to reproduce:
1. Inspect test page
2. Click the button to show the File picker
3. While the file picker is showing trigger a Garbage Collection in Inspector&apos;s Console
4. Complete the file picker dialog with a file
  =&gt; Alert doesn&apos;t happen

Notes:
• I was able to reproduce the issue in Chrome once. Unable to try Firefox.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1566128</commentid>
    <comment_count>1</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2019-08-29 00:07:26 -0700</bug_when>
    <thetext>Worked around this in Web Inspector: Bug 201289

But I wonder if this could affect a real page.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1566278</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-08-29 10:08:26 -0700</bug_when>
    <thetext>This is a weird one. Technically, JS no longer has access to the file element because it had lost access to all its references (it&apos;s not a part of the document). But perhaps there is an expectation that the event will fire when the user dismisses the dialog or picks a file.

The way to fix this problem is to deploy GCReachableRef&lt;HTMLInputElement&gt; I added.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1566516</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2019-08-29 19:26:53 -0700</bug_when>
    <thetext>It’s also similar to media elements and Fetch, whose wrappers stay alive in the expectation of callback making them visible again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1566548</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-08-29 21:39:21 -0700</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #3)
&gt; It’s also similar to media elements and Fetch, whose wrappers stay alive in
&gt; the expectation of callback making them visible again.

Yeah, in that sense, perhaps HTMLInputElement should be an ActiveDOMObject with a pending activity whenever there is a dialog popped up.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1566689</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2019-08-30 09:32:49 -0700</bug_when>
    <thetext>(In reply to Ryosuke Niwa from comment #4)
&gt; (In reply to Alexey Proskuryakov from comment #3)
&gt; &gt; It’s also similar to media elements and Fetch, whose wrappers stay alive in
&gt; &gt; the expectation of callback making them visible again.
&gt; 
&gt; Yeah, in that sense, perhaps HTMLInputElement should be an ActiveDOMObject
&gt; with a pending activity whenever there is a dialog popped up.

That sounds about right.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>