Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Website doesn't scroll to hash '#' in URL path, if present #78

Closed
trivikr opened this issue Oct 27, 2019 · 2 comments · Fixed by #104
Closed

Website doesn't scroll to hash '#' in URL path, if present #78

trivikr opened this issue Oct 27, 2019 · 2 comments · Fixed by #104

Comments

@trivikr
Copy link
Contributor

trivikr commented Oct 27, 2019

For example, the CONTRIBUTING.md links to contributing section of manual.md

When website loads https://deno.land/std/manual.md#contributing, it doesn't scroll to the contributing section

@trivikr
Copy link
Contributor Author

trivikr commented Oct 27, 2019

This happens as Registry.js doesn't consume hash parameter from useLocation()
https://github.com/denoland/deno_website2/blob/38c5c441d9562f9e9617a52f9509e70493b5ea33/src/Registry.js#L19

Registry.js can consume hash parameter for useLocation(), and scroll to that section on the page on load.
Documentation: https://reacttraining.com/react-router/web/api/Hooks/uselocation

@lucacasonato
Copy link
Member

For example, the CONTRIBUTING.md links to contributing section of manual.md

* Source: https://github.com/denoland/deno/blob/master/CONTRIBUTING.md

* Link: https://deno.land/std/manual.md#contributing

When website loads https://deno.land/std/manual.md#contributing, it doesn't scroll to the contributing section

This happens as Registry.js doesn't consume hash parameter from useLocation()

https://github.com/denoland/deno_website2/blob/38c5c441d9562f9e9617a52f9509e70493b5ea33/src/Registry.js#L19

Registry.js can consume hash parameter for useLocation(), and scroll to that section on the page on load.
Documentation: https://reacttraining.com/react-router/web/api/Hooks/uselocation

This is correct, but it is not related to the non-consumption of the hash - useLocation only makes the location available in the component, it does not actually trigger any logic when running the hook.

The root cause of the issue is actually that browsers like Chrome and Firefox, who handle the hash anchoring, only do this within a certain time period or before a certain browser specified metric trips. Because the content of the page is loaded asynchronously - because the page is client rendered - either the time period is over or the metric trips before the content is loaded. After this happens the browser stops trying to find the anchor and scroll it into view.

Anchoring does work if the content is there right away. You can see this yourself by going to the mentioned link and after the content has loaded, click on the url bar again and just press enter. This will re-trigger the anchoring process. The element should now be scrolled into view.

In any case we should definitely fix this as this is not intended behavior. I actually mentioned this exact issue in #70. A way to fix it would be to manually to do the anchoring in JS after the content has been loaded and rendered to the DOM. We need to implement this as a trigger on actual DOM render, which is not super fun in React.

More info: https://medium.com/@gajus/making-the-anchor-links-work-in-spa-applications-618ba2c6954a

ry added a commit to ry/deno_website2 that referenced this issue Nov 7, 2019
@ry ry closed this as completed in #104 Nov 7, 2019
ry added a commit that referenced this issue Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants