Skip to content

Commit 24638c6

Browse files
committed
Revert sidebar fix
1 parent 91d0864 commit 24638c6

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

src/components/Layout/Toc.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,16 @@
1010
*/
1111

1212
import cx from 'classnames';
13-
import {startTransition, useOptimistic} from 'react';
1413
import {useTocHighlight} from './useTocHighlight';
1514
import {IsInTocContext} from '../MDX/TocContext';
1615
import type {Toc} from '../MDX/TocContext';
1716

18-
function waitForScrollEnd(): Promise<void> {
19-
return new Promise((resolve) => {
20-
let settled = false;
21-
const finish = () => {
22-
if (settled) return;
23-
settled = true;
24-
window.removeEventListener('scrollend', finish);
25-
resolve();
26-
};
27-
window.addEventListener('scrollend', finish, {once: true});
28-
setTimeout(finish, 1000);
29-
});
30-
}
31-
3217
export function Toc({headings}: {headings: Toc}) {
3318
const {currentIndex} = useTocHighlight();
34-
const [optimisticIndex, setOptimisticIndex] = useOptimistic(currentIndex);
3519
// TODO: We currently have a mismatch between the headings in the document
3620
// and the headings we find in MarkdownPage (i.e. we don't find Recap or Challenges).
3721
// Select the max TOC item we have here for now, but remove this after the fix.
38-
const selectedIndex = Math.min(optimisticIndex, headings.length - 1);
22+
const selectedIndex = Math.min(currentIndex, headings.length - 1);
3923
return (
4024
<nav role="navigation" className="pt-20 sticky top-0 end-0">
4125
{headings.length > 0 && (
@@ -75,13 +59,7 @@ export function Toc({headings}: {headings: Toc}) {
7559
: 'text-secondary dark:text-secondary-dark',
7660
'block hover:text-link dark:hover:text-link-dark leading-normal py-2'
7761
)}
78-
href={h.url}
79-
onClick={() => {
80-
startTransition(async () => {
81-
setOptimisticIndex(i);
82-
await waitForScrollEnd();
83-
});
84-
}}>
62+
href={h.url}>
8563
{h.text}
8664
</a>
8765
</li>

0 commit comments

Comments
 (0)