fix: docs scroll

This commit is contained in:
Wayne Sutton
2025-12-30 12:24:36 -08:00
parent 6cd9ec116c
commit a5c30a1592
9 changed files with 45 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import NewsletterAdmin from "./pages/NewsletterAdmin";
import Dashboard from "./pages/Dashboard";
import Callback from "./pages/Callback";
import Layout from "./components/Layout";
import ScrollToTopOnNav from "./components/ScrollToTopOnNav";
import { usePageTracking } from "./hooks/usePageTracking";
import { SidebarProvider } from "./context/SidebarContext";
import siteConfig from "./config/siteConfig";
@@ -45,6 +46,7 @@ function App() {
return (
<SidebarProvider>
<ScrollToTopOnNav />
<Layout>
<Routes>
{/* Homepage route - either default Home or custom page/post */}

View File

@@ -99,10 +99,15 @@ export default function AIChatView({
initChat();
}, [sessionId, contextId, getOrCreateChat]);
// Auto-scroll to bottom when new messages arrive
// Auto-scroll to bottom when new messages arrive (only if there are messages)
useEffect(() => {
if (messagesEndRef.current) {
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
// Only scroll if there are actual messages (don't scroll on initial empty state)
if (messagesEndRef.current && chat?.messages && chat.messages.length > 0) {
// Use scrollTo on the parent container instead of scrollIntoView to avoid page scroll
const messagesContainer = messagesEndRef.current.parentElement;
if (messagesContainer) {
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
}
}, [chat?.messages]);

View File

@@ -0,0 +1,22 @@
import { useLayoutEffect } from "react";
import { useLocation } from "react-router-dom";
/**
* Scrolls to top of page on route changes
* Skips scroll if navigating to a hash anchor
* Uses useLayoutEffect to run before browser paint
*/
export default function ScrollToTopOnNav() {
const { pathname, hash } = useLocation();
// useLayoutEffect runs synchronously before browser paint
useLayoutEffect(() => {
// Skip if navigating to a hash anchor
if (hash) return;
// Scroll to top immediately (before paint)
window.scrollTo(0, 0);
}, [pathname, hash]);
return null;
}

View File

@@ -7,6 +7,11 @@ import { FontProvider } from "./context/FontContext";
import { isWorkOSConfigured } from "./utils/workos";
import "./styles/global.css";
// Disable browser scroll restoration to prevent scroll position being restored on navigation
if ("scrollRestoration" in window.history) {
window.history.scrollRestoration = "manual";
}
const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL);
// Lazy load the appropriate App wrapper based on WorkOS configuration