Generate file permalink without reloading the page

Problem to solve

When I am viewing a file and want to generate a permalink, and I use the y shortcut, the whole page is reloaded. This is slow. Why can't the URL in the browser simply be updated immediately since the page content doesn't really need to change?

Further details

This is already a feature of GitHub is a definitely nice polish

Proposal

Switch to permalink without reloading the page

Implementation Details

Phase 1

For this issue, we'll cover two new behaviors (both in service of the no-reload permalink feature):

  1. We change the behavior of the permalink navigation code to use history.pushState to update the URL (and the associated history item) to the permalink URL.
  2. We add an additional piece of small code to update the title to include the SHA instead of the branch name.

Phase 2

In a later iteration, we'll:

  1. Bind a popState listener when the permalink is triggered, so that the browser back button will properly unset the SHA from the window title, and potentially other reverting behavior, too.

Phase 3

In potentially the final iteration (see below), we'll:

  1. Update the entire page with the permalink SHA. There are a lot of discrete URLs scattered throughout the page that need to be updated (and reverted, assuming the back button is pressed) and there's no clear way to do that all at once. This update may require some exploratory work to figure out the best (most future-friendly, least intrusive, etc.) way to scan the whole page and update all of the links.

Future iterations

image

  1. Handle pressing the back button
    1. Change page title back to the branch name
    2. Change URL back to the non-permalink
  2. The selected ref dropdown changes to the commit of the permalink
  3. Some file header buttons become disabled
  4. Some repo-level buttons change their URL structure to adapt to the permalink

Links / reference

https://serokell.io/blog/comparison-of-github-and-gitlab

Edited by Thomas Randolph