Ref T3612. Doesn't render correctly, need help please. Adds a download icon into the renderfilelinkview to allow easier downloads.
Details
- Reviewers
epriestley - Maniphest Tasks
- T3612: Lightbox v2
- Commits
- rP489587d60734: Add download link to embedded files
Click on link, get download, click on file, get lightbox.
Diff Detail
- Repository
- rP Phabricator
- Branch
- file-embed-download (branched from master)
- Lint
Lint Passed - Unit
Tests Passed - Build Status
Buildable 15089 Build 19806: Run Core Tests Build 19805: arc lint + arc unit
Event Timeline
Getting a double render here I think, not sure what I'm setting incorrectly (the form triggers it).
If there is no easy way to do this, lmk, I'll just maybe re-think if Files should be lightboxable at all.
The browser inspector is misleading. The issue is that we're emitting this HTML:
<a href="http://local.phacility.com/file/data/@local/egwoplzjb6feujagzrj4/PHID-FILE-eb73u3bajy7emc3i22yg/psyduck.png" class="phabricator-remarkup-embed-layout-link " data-sigil="lightboxable" data-meta="0_26" data-mustcapture="1" rel="noreferrer"> <span class="visual-only phui-icon-view phui-font-fa fa-file-picture-o" aria-hidden="true"></span> <span class="phabricator-remarkup-embed-layout-info-block"> <span class="phabricator-remarkup-embed-layout-name">psyduck.png</span> <span class="phabricator-remarkup-embed-layout-info">490 KB</span> </span> <form action="#" method="POST" class="embed-download-form" data-sigil="embed-download-form"> <input type="hidden" name="__csrf__" value="B@qw2kw2zt247d96d8816fcd9a" /> <input type="hidden" name="__form__" value="1" /> <a class="phui-icon-circle hover-green" href="#"> <span class="visual-only phui-icon-view phui-font-fa fa-download" aria-hidden="true"></span> </a> </form> </a>
More simply:
<a><form><a>...</a></form></a>
I think you can't have a form in a link, and you definitely can't have a link in a link.
I think browsers are silently reorganizing the outer <a> and <form> tags to be valid, which makes it appear that a double render has occurred.
Changing getTagName() to div instead of a fixes the apparent double render (although we'll need more work to make the element actually work).
This took me a bit, but here's how I ultimately figured this out:
- Changed renderFileLink() to return this:
return array( "\n\n\n", $view, "\n\n\n", );
- Looked at the raw page source. The DOM inspector sometimes lies about this stuff, and reflects changes made by Javascript. You can compare the DOM inspector to the raw source to find problems caused by Javascript or by bad HTML tag soup: if the raw page source looks good but the DOM inspector looks broken, either the browser "fixed" something for you or the problem is with some kind of JS thing.
- Copy/pasted the separated block of stuff of raw source stuff into my text editor.
- Manually reformatted the tags to be readable, revealing the <a><form><a>.
This "improvement" to the source is particularly bizarre and I haven't seen browsers make it before but I guess we learned something new today?
I think this all works as expected, though downloading the file now changes submit button to 0.5 opacity and never clears and I'm not sure how to skip that feature.
Alternatively, I believe you can add the sigil download to stop the disable-on-submit behavior.