-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat(theme-classic): reintroduce autoscrolling TOC #6666
base: main
Are you sure you want to change the base?
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6666--docusaurus-2.netlify.app/ |
@yangshun I think this fixes it. You can test here: https://deploy-preview-6666--docusaurus-2.netlify.app/tests/docs/more-test/ or on any other page |
@@ -46,6 +46,7 @@ const DEFAULT_CONFIG = { | |||
minHeadingLevel: 2, | |||
maxHeadingLevel: 3, | |||
}, | |||
autoScrollTOC: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep this undocumented for now, probably not useful for most people, as their sites don't work because of broken CSS in the first place...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Oops, not entirely good. The back-to-top button doesn't work |
Ah, it's caused by our smooth scrolling polyfill, which supabase gets around by removing the BTT button altogether. @slorber What do you think about here? Should we use |
Looks Great on the new changes! |
Okay, BTT button fixed with some hacks... |
Great! Everything is working fine and the documents have no bugs. |
smooth scrolling is still sometimes interrupted on lower performance machines (dropped frames?). using a higher value on the timeout e.g. 100, 250 doesn't seem to visibly affect the perceived display of the active toc item (at least in my opinion), while significantly lowering the chance of interruption on slower machines |
@duanwilliam Good point. Turned the timeout up to 200, and the behavior is fine. |
Is it sure that this will be working on all browsers and systems, Does any system or browser will find bugs? @Josh-Cena |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks to me quite complex, hard to review/test and with a lot of moving parts for such a tiny toc highlighting feature 🤷♂️
I'd rather plainly disable this feature (or make it opt-in, default to false) until we can find a good implementation for it, as implementing and reviewing this properly prevents us to focus on 2.0 which is way more important.
This new implementation breaks TOC navigation.
This is what I get when clicking on "Crowdin Overview" in the TOC while at the bottom of this page: https://deploy-preview-6666--docusaurus-2.netlify.app/docs/i18n/crowdin/#example-configuration
The clicked TOC heading now appears under the navbar and is not visible anymore
@@ -37,18 +37,29 @@ function smoothScrollTopNative(): CancelScrollTop { | |||
|
|||
function smoothScrollTopPolyfill(): CancelScrollTop { | |||
let raf: number | null = null; | |||
// Coercing to auto scroll to prevent conflicts with scroll-behavior. | |||
// This is a polyfill for browsers without smooth scrolling anyways. | |||
document.documentElement.style.scrollBehavior = 'auto'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a previous value is already set, will it be properly restored?
What's the impact of not restoring it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no other case where a style is inlined in the DOM. I don't believe any userland code would do that instead of using :root
selector. We need to force using scroll-behavior: auto
, because otherwise CSS and JS would scroll the page simultaneously and cancel each other, as is the entire purpose of sending this PR.
window.scrollTo(0, 0); | ||
document.documentElement.style.scrollBehavior = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, restore previous value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no previous value.
) { | ||
link.scrollIntoView({block: 'nearest', behavior: 'smooth'}); | ||
} | ||
}, 200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic timeout values like that are a recipe for troubles 😅 I'd like to avoid it at all cost
What about waiting for the end of scroll events using debounce + trailing events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, even if you are debouncing, you have to debounce within a certain time range, right? This is essentially a debounce.
} | ||
const handle = setTimeout(() => { | ||
const linkRect = link.getBoundingClientRect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this code is quite low-level, please extract it under a meaningful function name that convey intent, and allowing us to more easily migrate to the official "if-needed" feature later?
scrollIntoView(node, {
scrollMode: 'if-needed',
block: 'nearest',
behavior: 'smooth'
})
Maybe using this package? https://github.com/stipsan/scroll-into-view-if-needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not if-needed. It's the exact opposite: we don't scroll if we have to do a horizontal scroll. We don't care if we do a moot scroll, but we don't want the scroll to be horizontal.
It has nothing to do with this fix. It's because of the We are mainly just interested in fixing the JS and empowering users to use |
It started as a quick fix for the autoscrolling TOC with |
Can we split this into separate PRs so that we can understand exactly what is the purpose and impact of each piece of code? It will help me review it because in current state 🤷♂️ Remember I want to focus on 2.0 so I can't spend too much time on this PR Can we have the most important fix (#6620) merged immediately, and figure it out later for the smooth scroll which is useful but less important? |
@slorber, @Josh-Cena |
#6317 Reimagined. Reverts #6748
This is Pull Request in order to fix this issue and bring the website a better user experience.
This PR:
autoScrollTOC
config optionscroll-behavior: smooth
to the website, both for dogfooding and better UX