Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #13653 #65581

Open
wants to merge 7 commits into
base: canary
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,26 @@ class Container extends React.Component<{
})
}
}

componentDidUpdate() {
this.scrollToHash()

//Changes to be reviewed - To ensure that the component scrolls to the appropriate element even when the user navigates using the browser buttons
componentDidUpdate(prevProps) {
if (prevProps.location.hash !== this.props.location.hash) {
this.scrollToHash();
}
}

scrollToHash() {
let { hash } = location
hash = hash && hash.substring(1)
if (!hash) return
scrollToHash() {
let { hash } = this.props.location;
hash = hash && hash.substring(1);
if (!hash) return;

const el: HTMLElement | null = document.getElementById(hash)
if (!el) return
const el = document.getElementById(hash);
if (!el) return;

// If we call scrollIntoView() in here without a setTimeout
// it won't scroll properly.
setTimeout(() => el.scrollIntoView(), 0)
}
// If we call scrollIntoView() in here without a setTimeout
// it won't scroll properly.
setTimeout(() => el.scrollIntoView(), 0);
}

render() {
if (process.env.NODE_ENV === 'production') {
Expand Down