web-infra-dev / rspress

πŸ¦€πŸ’¨ A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.19k stars 108 forks source link

fix(theme-default): scroll restoration #1181

Closed shulaoda closed 1 week ago

shulaoda commented 1 week ago

Summary

The issue arises due to the browser's default behavior of history.scrollRestoration, which restores the scroll position upon refresh to enhance the user experience. I changed this default behavior in theme-default to avoid affecting other custom templates. However, if there is no anchor in the link, it affects the refresh experience to some extent. If we consider that it only works when there is an anchor, it will make the problem more complex.

Related Issue

closed #1154

Checklist

netlify[bot] commented 1 week ago

Deploy Preview for aquamarine-blini-95325f ready!

Name Link
Latest commit bcc092bb3d0a31b336d4317ace6539e8b6f775f3
Latest deploy log https://app.netlify.com/sites/aquamarine-blini-95325f/deploys/666a8d5b455b150008afe943
Deploy Preview https://deploy-preview-1181--aquamarine-blini-95325f.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

Lighthouse
1 paths audited
Performance: 83 (πŸ”΄ down 8 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Timeless0911 commented 1 week ago

If we don’t click the anchor so that the url does not contain location.hash(#abc), then the performance after refreshing the page will indeed damage the user’s reading experience.

Only works when there is an anchor is necessary I think. Just check whether the current pathname contains location.hash?

Timeless0911 commented 1 week ago

LGTM