mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(site): preserve scroll position on framework switch (pagereveal) (#608)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1c6293ea39
commit
420742e7c9
@@ -17,7 +17,6 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function JSPickerClient({ currentFramework, currentStyle, currentSlug }: Props) {
|
||||
// TODO: use astro view transitions to preserve scroll position when switching from the same slug to the same slug
|
||||
const handleFrameworkChange = (newFramework: SupportedFramework | null) => {
|
||||
if (newFramework === null) return;
|
||||
if (!isValidFramework(newFramework)) return;
|
||||
@@ -30,10 +29,20 @@ export default function JSPickerClient({ currentFramework, currentStyle, current
|
||||
});
|
||||
|
||||
if (shouldReplace) {
|
||||
// Maintaining the current slug, navigate without pushing onto the history stack
|
||||
// Base UI's scroll lock transfers html.scrollTop → body.scrollTop
|
||||
const scrollLocked = document.documentElement.hasAttribute('data-base-ui-scroll-locked');
|
||||
const scrollY = scrollLocked ? document.body.scrollTop : window.scrollY;
|
||||
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
'vjs-page-scroll',
|
||||
JSON.stringify({ url: new URL(url, window.location.origin).pathname, scrollY })
|
||||
);
|
||||
} catch {
|
||||
// Ignore storage errors
|
||||
}
|
||||
window.location.replace(url);
|
||||
} else {
|
||||
// Changing slug, use normal navigation
|
||||
window.location.href = url;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user