mirror of
https://github.com/waynesutton/markdown-site.git
synced 2026-01-12 04:09:14 +00:00
fix: docs scroll
This commit is contained in:
@@ -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 */}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
22
src/components/ScrollToTopOnNav.tsx
Normal file
22
src/components/ScrollToTopOnNav.tsx
Normal 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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user