Skip to content

Instantly share code, notes, and snippets.

@robertknight
Created July 7, 2022 10:37
Show Gist options
  • Save robertknight/4afaabbb35d4126c2705251febb55847 to your computer and use it in GitHub Desktop.
Save robertknight/4afaabbb35d4126c2705251febb55847 to your computer and use it in GitHub Desktop.
How Hypothesis interacts with canonical links (`<link rel=canonical>`)
@kael
Copy link

kael commented Jul 7, 2022

Do we have workarounds for the above problems?

In the H client, there could be 2 new fields which would display the URI and its canonical URL to be bookmark. Users would be able to edit them, although it's prone to voluntary discrepancies if someone were in a bad mood.

What about using MutationObserver to detect location-change ? Upon location change, the H client could force-reload the page so that an SSR version of the page is returned with the correct canonical URL.

@robertknight
Copy link
Author

Users would be able to edit them, although it's prone to voluntary discrepancies if someone were in a bad mood.

I think we need to be able to solve this without any user input. The situation would be pretty difficult to explain in simple terms to someone who doesn't know what canonical links are.

What about using MutationObserver to detect location-change ?

Yes, this is planned. hypothesis/client#4629 uses a combination of window.navigation (if available), monkey-patching window.history (otherwise) and MutationObserver to detect changes in the browser URL and links in the <head> element.

I'm currently doing some investigation to understand how canonical URLs are used in the wild and get an understanding of how many sites are affected by this or related issues. Reloading the page might work, but it would also lose some state and make the navigation slower, so I'd prefer to avoid that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment