Clicking an attachment link works only once

AI-generated summary

A bug was reported by gerhard regarding attachment links in Discourse, where clicking a download link works only once. Subsequent clicks fail until the page is reloaded. This issue was observed in Chrome 40 on Windows for logged-in users (affecting all links) and for visitors (affecting only the first link), while Internet Explorer 11 appeared unaffected. codinghorror suggested this might be a bug for zogstrip to investigate. elberet identified the root cause: on subsequent clicks, window.getSelection() returns an empty range, which incorrectly triggers a check in the TopicView. zogstrip confirmed the fix with a commit link, resolving the issue.

Steps to reproduce:

Expected behavior:
Each click on the download link should start a download.

Actual behavior:
Only the first click starts a download. All subsequent click do nothing. After reloading the page the first click works again.

Notes:
I’ve seen this behavior in Chrome 40 on Windows. In IE11 it seems to work as expected.
When you’re logged in this bug occurs for each download link. As visitor it affects only the first download link that you click.

This is possibly related to
https://meta.discourse.org/t/when-external-links-set-to-open-in-new-tab-link-cannot-be-clicked-twice/21015

2 Likes

Possibly a bug for you to look at @zogstrip.

For some reason, on subsequent clicks window.getSelection() includes an empty range which trips up the check in the TopicView. (Tested on Chrome 40.0.2214.93 m / Win8.1)

2 Likes

This should fix the issue :cat2:

https://github.com/discourse/discourse/commit/b809e02c6c43b92f618e9532b4c08e30f20fe4f8

3 Likes