-
-
Notifications
You must be signed in to change notification settings - Fork 768
fix: mobile toc issue with custom banners #3382
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: fe3b4cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com> Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
Description
This PR fixes an issue with the Table of Contents being unable to find any heading when the page has a banner with custom styling. This issue is currently tracked in #3047.
The issue is fixed by introducing a temporary
IntersectionObserver
without anyrootMargin
(so that it definitely gets an intersection target). This new code only runs when there is no other intersecting target found by the existingIntersectionObserver
.Visit https://deploy-preview-3382--astro-starlight.netlify.app/getting-started/ and make the screen a smaller to see the mobile ToC, then reload and see that a current heading is set.
Please note that this issue could also be resolved in some other ways of course and I'm not sure if introducing a second
IntersectionObserver
is a good practice just for this edge case. Feel free to suggest cleaner solutions!Another considered solution
Another solution that came to my mind, but where I figured that it has too many side effects (and therefore I didn't commit to it): By dynamically incorporating the actual height of the banner in the calculation of
bottom
it would be possible to always guarantee that a heading can be found (which would mean that we don't need a second observer). However, the problem with that approach would be that the observer would then permanently be too big and headings would "too early" be considered current headings. For example: If the banner is really big, headings that scroll into the middle of the screen could potentially be set as the "current" headings in the ToC, which would be misleading.To demonstrate what I mean with this paragraph in code:
starlight/packages/starlight/components/TableOfContents/starlight-toc.ts
Line 107 in 2768932
Related stuff and todo