This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
Handle scrolling to hash on page transition #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Browsers only automatically scroll to the URL hash on page load. Since we're doing client-side transitions, we need to handle that ourselves. Normally, Next.js would take care of that for us: https://github.com/zeit/next.js/blob/0b496a45e85f3c9aa3cf2e77eef10888be5884fc/packages/next/client/index.js#L112. However, since we have transitions, the element with the ID referenced by the hash doesn't actually exist when the page change "completes" from the perspective of Next.js, the automatic scrolling fails. This PR will attempt to scroll to the element referenced by the hash as soon as we know that the page is in the DOM after it starts transitioning in.
Fixes #35.