web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.19k stars 108 forks source link

[Bug]: Aside activate wrongly when refresh page which contain anchor hash in URL #1154

Closed declanchiu closed 1 week ago

declanchiu commented 3 weeks ago

版本信息

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 146.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 125.0.6422.142
    Safari: 17.5
  npmPackages:
    rspress: ^1.23.0 => 1.23.0

问题详情

image

After memorizing an anchor point, why doesn't it jump to the specific anchor point after refreshing, and why is the right side highlighted in the wrong place?

复现链接

https://rspress.dev/guide/advanced/custom-search#aftersearch

复现步骤

  1. Click on one of the document's anchor points

  2. The current url records the anchor.

  3. Refresh the page according to the current url

  4. Finds the problem mentioned above

Timeless0911 commented 3 weeks ago

I can't reproduce.

20240605191321_rec_

declanchiu commented 2 weeks ago

I can't reproduce. 我无法重现。

录屏2024-06-06 09 50 28 (1)

Thanks for trying to reproduce it, but the way I see it in the gif is a bit different, the correct way to do it is to click on an anchor and then scroll away from the current anchor, for example after clicking on the last anchor, the url is spliced with the anchor, then scroll to the top of the page, then refresh the page and you can see that the url with the anchor doesn't scroll to the bottom after refreshing! The

Timeless0911 commented 2 weeks ago

Thanks. From your gif, I see two main issues you want to point it out.

  1. After scrolling to the top, refreshing the page again does not redirect to the corresponding anchor position. This should be a bug
  2. Clicking the Differences from VitePress label in aside component, the highlighted label is Try Rspress. This is the expected behavior because it has reached the bottom of the page and the content of the two labels fills the screen, so the last label Try Rspress is highlighted. You can try it at https://vitepress.dev/reference/runtime-api#frontmatter, and the same behaviour when in this scene.
Timeless0911 commented 2 weeks ago

This bug is caused by extra setActiveLink() which is implemented to fix right aside nav item doesn't highlight automatically while opening in a new tab in #319

https://github.com/web-infra-dev/rspress/blob/90fc852c04a63e48d1cf2e489dcf5d03b7c2bfec/packages/theme-default/src/logic/sideEffects.ts#L168

We need to deal both same page refresh and open new tab well.