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

Instant navigation: toc item requires two clicks after navigating away and returning #7183

Closed
4 tasks done
rachel-rigdon-sp opened this issue May 14, 2024 · 5 comments
Closed
4 tasks done
Labels
bug Issue reports a bug 🏆 perfect Issue is of outstanding quality resolved Issue is resolved, yet unreleased if open

Comments

@rachel-rigdon-sp
Copy link
Contributor

rachel-rigdon-sp commented May 14, 2024

Context

No response

Bug description

When using Instant Loading, selecting a link in the table of contents, navigating away, returning, and then selecting the same toc item does not jump to the id until the second click.

I've confirmed this in Chrome, Firefox, and Edge.

Related links

Reproduction

9.5.22+insiders.4.53.8-instant-nav-bug-repro.zip

Steps to reproduce

  1. Select a right-side toc item.
  2. Use the left-side navigation to go to another page.
  3. Use the left-side navigation to return to the first page.
  4. Select the same right-side toc item. It now requires two clicks to navigate to.

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

Thanks for reporting! I'll investigate.

@squidfunk squidfunk added the bug Issue reports a bug label May 15, 2024
@squidfunk squidfunk changed the title Selecting a toc item requires two clicks after navigating away and returning Instant navigation: toc item requires two clicks after navigating away and returning May 15, 2024
@squidfunk
Copy link
Owner

Fixed in 485fa76! Thanks for the excellent issue and reproduction, that made isolating and fixing the issue really easy. The problem was that the pathname change was not properly detected, which is now ensured by the document$ subscription and the double switch map on location$. The comment explains how it works:

// Handle instant navigation events that are triggered by the user clicking
// on an anchor link with a hash fragment different from the current one, as
// well as from popstate events, which are emitted when the user navigates
// back and forth between pages. We use a two-layered subscription to scope
// the scroll restoration to the current page, as we don't need to restore
// the viewport offset when the user navigates to a different page, as this
// is already handled by the previous observable.
document$.pipe(
switchMap(() => location$),
distinctUntilKeyChanged("pathname"),
switchMap(() => location$),
distinctUntilKeyChanged("hash")
),

Perfect issue! Thanks for taking the time.

@squidfunk squidfunk added resolved Issue is resolved, yet unreleased if open 🏆 perfect Issue is of outstanding quality labels May 15, 2024
@rachel-rigdon-sp
Copy link
Contributor Author

Thank you so much for the fix! 🙌🏻

@squidfunk
Copy link
Owner

Released as part of 9.5.23.

@soronpo
Copy link

soronpo commented May 19, 2024

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug 🏆 perfect Issue is of outstanding quality resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants