From 4ec1c93e95d79daa84018b9bb0f84f03ba0f4dee Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 8 Aug 2024 14:44:06 +0800 Subject: [PATCH] fix: scroll to top when switch to other entry Signed-off-by: Innei --- src/renderer/src/modules/entry-content/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/modules/entry-content/index.tsx b/src/renderer/src/modules/entry-content/index.tsx index 37a177ea9..72fab596e 100644 --- a/src/renderer/src/modules/entry-content/index.tsx +++ b/src/renderer/src/modules/entry-content/index.tsx @@ -29,7 +29,7 @@ import { Queries } from "@renderer/queries" import { useEntry, useEntryReadHistory } from "@renderer/store/entry" import { useFeedById, useFeedHeaderTitle } from "@renderer/store/feed" import type { FC, ReactNode } from "react" -import { useEffect, useLayoutEffect, useState } from "react" +import { useEffect, useLayoutEffect, useRef, useState } from "react" import { LoadingCircle } from "../../components/ui/loading" import { EntryPlaceholderDaily } from "../ai/ai-daily/EntryPlaceholderDaily" @@ -136,6 +136,11 @@ function EntryContentRender({ entryId }: { entryId: string }) { const view = useRouteParamsSelector((route) => route.view) const isInReadabilityMode = useEntryIsInReadability(entryId) + const scrollerRef = useRef(null) + + useEffect(() => { + scrollerRef.current?.scrollTo(0, 0) + }, [entryId]) if (!entry) return null return ( @@ -155,6 +160,7 @@ function EntryContentRender({ entryId }: { entryId: string }) { mask={false} rootClassName="h-0 grow min-w-0 overflow-y-auto @container" viewportClassName="p-5" + ref={scrollerRef} > { + setEntryContentScrollToTop(false) + }, [entryId]) useLayoutEffect(() => { setEntryContentScrollToTop(atTop) }, [atTop])