Skip to content

Commit 987cff4

Browse files
committed
properly reobserve the new page post-navigation so the page nav picker updates during scroll on mobile
this is because the page doesnt actually remount, we reuse the existing component tree
1 parent c7c7a30 commit 987cff4

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

packages/dev/s2-docs/src/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ function Toc({toc}) {
184184
);
185185
}
186186

187-
function MobileToc({toc}) {
187+
function MobileToc({toc, currentPage}) {
188188
return (
189-
<MobileOnPageNav>
189+
<MobileOnPageNav currentPage={currentPage}>
190190
{renderMobileToc(toc)}
191191
</MobileOnPageNav>
192192
);

packages/dev/s2-docs/src/Nav.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,11 @@ export function OnPageNav({children}) {
209209
);
210210
}
211211

212-
export function MobileOnPageNav({children}) {
212+
export function MobileOnPageNav({children, currentPage}) {
213213
let [selected, setSelected] = useState('');
214-
215214
useEffect(() => {
216215
let elements = Array.from(document.querySelectorAll('article > :is(h1,h2,h3,h4,h5)'));
217216
elements.reverse();
218-
219217
let visible = new Set();
220218
let observer = new IntersectionObserver(entries => {
221219
for (let entry of entries) {
@@ -244,7 +242,7 @@ export function MobileOnPageNav({children}) {
244242
}
245243

246244
return () => observer.disconnect();
247-
}, []);
245+
}, [currentPage]);
248246

249247
return (
250248
<Picker aria-label="Table of contents" selectedKey={selected} isQuiet size="L">

0 commit comments

Comments
 (0)