WIP: Fix "Permalink" button in Firefox
What does this MR do?
Fixes the issue described in #31374 (closed) by extending a setTimeout
(from 0ms
to 50ms
) used to wait for the URL's hash parameter to change.
Context
The href
of the Permalink button on the blob view page (e.g. a page like this: https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab-ci.yml) is updated by a small JavaScript function whenever a line number is clicked so that the line number hash (i.e. #L23
) is persisted when the user clicks the Permalink button.
This process works like this:
- The users clicks a line number (for example, line 23)
- This triggers a
click
handler attached by theLineHighlighter
class which updates the URL with the#L23
parameter - This also triggers a second
click
handler attached by theBlobLinePermalinkUpdater
class which copies the hash parameter from the URL to thehref
of the Permalink button. This is done in asetTimeout
so that the URL is updated by the firstclick
handler before this secondclick
handler is executed.
However, for whatever reason, 0ms
isn't always enough time for Firefox to update the URL - and this causes the Permalink button to not receive the updated query parameter. Perhaps updating the URL has been changed to be an asynchronous operation in newer versions of Firefox?
Interestingly enough, this bug only occurs in Firefox without the dev tools open.
GIF
TODO: Add GIF
Other ways we could fix this
I played around with removing the dependency on the URL in BlobLinePermalinkUpdater
, but this led to a much more drastic change and an unwanted coupling between BlobLinePermalinkUpdater
and LineHighlighter
.
We may need to more seriously consider this option if we still notice this bug after the bump to 50ms
.
Closes #31374 (closed)