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

Page refresh scroll bar position. #4506

Closed
4 tasks done
hacxy opened this issue Jan 22, 2025 · 2 comments
Closed
4 tasks done

Page refresh scroll bar position. #4506

hacxy opened this issue Jan 22, 2025 · 2 comments
Labels
bug: pending triage Maybe a bug, waiting for confirmation

Comments

@hacxy
Copy link

hacxy commented Jan 22, 2025

Describe the bug

Question 1:
When I refresh the browser while reading a document, the scrollbar is at the top before the page is fully loaded, which means scrollY is 0. It then returns to the last reading position. This process is not smooth visually, as there is a relatively long interval in the middle.

I also found that the VitePress documentation site has the same issue.

Question 2:
How to make the scrollbar not return to the last position after refreshing the browser, but always stay at the top?

Because I am developing a VitePress theme, as shown in the screenshot of question one, it shows that after the page is loaded, a line-by-line display animation effect will be played. If the scrollbar returns to the last position, then when the animation has not yet played into the visible area, there will be a period of blank content, so I hope to find a method that can make the page always return to the top each time the page is refreshed.

Reproduction

repo: https://github.com/hacxy/vitepress-theme-mild

Expected behavior

Provide option to disable the scrollbar returning to the position before refreshing the page after refreshing.

System Info

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M2
    Memory: 81.88 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.16.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.15.0 - ~/.nvm/versions/node/v20.16.0/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.1.1

Additional context

No response

Validations

@hacxy hacxy added the bug: pending triage Maybe a bug, waiting for confirmation label Jan 22, 2025
@hacxy hacxy closed this as completed Jan 22, 2025
@brc-dd
Copy link
Member

brc-dd commented Jan 22, 2025

To disable:

// .vitepress/theme/index.ts

import Theme from 'vitepress/theme'

if (typeof history !== 'undefined') {
  history.scrollRestoration = 'manual'
}

export default Theme

I don't think there is any way to make it less glitchy. For example on github it's the same:

Screen.Recording.2025-01-22.at.9.44.59.PM.mov

@hacxy
Copy link
Author

hacxy commented Jan 23, 2025

To disable:

// .vitepress/theme/index.ts

import Theme from 'vitepress/theme'

if (typeof history !== 'undefined') {
history.scrollRestoration = 'manual'
}

export default Theme
I don't think there is any way to make it less glitchy. For example on github it's the same:

Screen.Recording.2025-01-22.at.9.44.59.PM.mov

Thank you very much, I am using this method and have turned it off, and it looks very good at the moment.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: pending triage Maybe a bug, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants