swiftlang / swift-org-website

Swift.org website
https://swift.org
Other
477 stars 187 forks source link

Cmd + Left-click does not open links in new tab #18

Open alexandersandberg opened 2 years ago

alexandersandberg commented 2 years ago

Congratulations on open-sourcing swift.org! πŸŽ‰ I think it's a great decision to involve the community in this project. Looking forward to helping out in any way I can. πŸ™‚

Describe the bug I noticed that Cmd (⌘) + Left-click does not open (internal) links in a new tab. External links work fine.

Update: It seems like this also happens on external links (but not always?). I experienced it at https://www.swift.org/blog/swift-async-algorithms/ while clicking the links at the bottom in the Related Proposals section.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://www.swift.org/blog/website-open-source/
  2. Hold Cmd (⌘) and left-click on any internal link, e.g. Swift website work group (SWWG) in the first section

Expected behavior The clicked link should open in a new tab behind the current one, but instead, it opens in the same tab, replacing the current location.

If you disable JavaScript, the link opens correctly in a new tab (see video below).

Video

https://user-images.githubusercontent.com/35671299/160276053-f0d1c926-bbb0-4b64-bd20-77ad2fe7b979.mp4

Desktop (please complete the following information):

Additional context As I expected, this issue is coming from one of the JS scripts.

I'm suspecting https://github.com/cferdinandi/gumshoe is the culprit. I notice the website is using an old version (3.0.0) of gumshoe, so updating might fix the issue. I tried to run the website locally on my M1 mac to update gumshoe and see if it fixes it, but I ran into issues with Ruby.

Edit: See https://github.com/apple/swift-org-website/issues/18#issuecomment-1108303016 for an update.

alexandersandberg commented 2 years ago

I looked into this further after successfully running the project locally.

It appears that this is actually not an issue with the gumshoe dependency, but rather an issue with the analytics script used on the website.

More specifically, this line in base.html:

<script src="https://developer.apple.com/assets/metrics/scripts/analytics.js"></script>

After removing this script, Cmd + Left-click behaves as expected.

I'm guessing this script is used across multiple Apple products and/or websites and is not necessarily part of this project? Therefore, it might be best to move this issue to another (internal?) repo.


P.S. I also noticed that this analytics script exists in assets/javascripts/vendor/s_code_h.js but is unused. I'm guessing this was used before being replaced by the hosted version. This old script could probably be removed.

alexandersandberg commented 2 years ago

@shahmishal Assigning this issue to you as we discussed internally that you would take a look at it. Let me know if I can help you out! πŸ™‚

alexandersandberg commented 8 months ago

I had a look at this again, and it still seems like it's the analytics script that's causing the issue.

During development, the Cmd-click works because this script is not included. However, if you flip this if statement in base.html, it stops working again.

{% if jekyll.environment != 'development' %}
<script src="https://developer.apple.com/assets/metrics/scripts/analytics.js"></script>
...
{% endif %}

As soon as you remove that line, it works again.

natikgadzhi commented 2 months ago

I clicked around and it seems to work fine today in Chromium (Arc) on internal links. Fixed upstream?

alexandersandberg commented 2 months ago

I clicked around and it seems to work fine today in Chromium (Arc) on internal links. Fixed upstream?

I'm still seeing this issue in Safari Version 17.6 (19618.3.11.11.5).