Skip to content

fix(v2): do not focus on skip link if page refreshed - #4797

Merged
slorber merged 2 commits into
masterfrom
lex111/iss4794
May 18, 2021
Merged

fix(v2): do not focus on skip link if page refreshed#4797
slorber merged 2 commits into
masterfrom
lex111/iss4794

Conversation

@lex111

@lex111 lex111 commented May 15, 2021

Copy link
Copy Markdown
Contributor

Motivation

Fixes #4794

Using more reliable logic to determine that the route has actually changed (currently, there are false positives on reloads of same page).

As a result, the scroll position is lost during hot reloading.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

See To Reproduce section in #4794

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label May 15, 2021
@lex111
lex111 requested a review from slorber as a code owner May 15, 2021 12:53
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 15, 2021
@netlify

netlify Bot commented May 15, 2021

Copy link
Copy Markdown

[V1]

Built with commit ef838fe

https://deploy-preview-4797--docusaurus-1.netlify.app

@netlify

netlify Bot commented May 15, 2021

Copy link
Copy Markdown

[V2]

Built with commit ef838fe

https://deploy-preview-4797--docusaurus-2.netlify.app

@github-actions

github-actions Bot commented May 15, 2021

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 87
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4797--docusaurus-2.netlify.app/

@github-actions

github-actions Bot commented May 15, 2021

Copy link
Copy Markdown

Size Change: +128 B (0%)

Total Size: 640 kB

Filename Size Change
website/build/assets/css/styles.********.css 88.4 kB -39 B (0%)
website/build/assets/js/main.********.js 463 kB +151 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62 kB +8 B (0%)
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 26.9 kB +8 B (0%)

compressed-size-action

const initialPathname = useRef(pathname);

useEffect(() => {
if (pathname !== initialPathname.current) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to work on most cases but what if user is on /a, navigates to /b, and then navigates back to /a?

I think you should rather use a hook like usePrevious to make sure that the callback fires even if the user goes back to the page that was initially loaded

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise that looks like to fix the problem! thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you reproduce this issue on the preview site? Currently, when navigating back to initially loaded page, useEffect fires as expected.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'm sorry, didn't notice that you reassigned initialPathname to latest route.

So somehow you already handle that case, it's just that I'm not fan of the naming "initialPathname" considering its value is changed over time. Will change change the name and merge

@slorber
slorber merged commit 0360364 into master May 18, 2021
@slorber
slorber deleted the lex111/iss4794 branch August 17, 2021 17:49
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* fix(v2): do not focus on skip link if page refreshed

* rename ref

Co-authored-by: slorber <lorber.sebastien@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hot reload not working correctly (browser scrolls to top)

3 participants