Skip to content

Commit d05f122

Browse files
wesbillmanPinky
andauthored
fix(desktop): preserve timeline scroll when opening threads (#1278)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent 73cc31c commit d05f122

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ export const ChannelPane = React.memo(function ChannelPane({
669669
hasComposerOverlay={hasMainComposerOverlay}
670670
hasOlderMessages={hasOlderMessages}
671671
isFetchingOlder={isFetchingOlder}
672+
layoutShiftKey={
673+
useSplitAuxiliaryPane ? (openThreadHeadId ?? "closed") : "overlay"
674+
}
672675
isFollowingThreadById={isFollowingThreadById}
673676
isMessageUnreadById={isMessageUnreadById}
674677
personaLookup={personaLookup}

‎desktop/src/features/messages/ui/MessageTimeline.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type MessageTimelineProps = {
5050
/** True when the timeline has the composer overlay below it. */
5151
hasComposerOverlay?: boolean;
5252
isFetchingOlder?: boolean;
53+
layoutShiftKey?: string | number | null;
5354
messageFooters?: Record<string, React.ReactNode>;
5455
/** Map from lowercase pubkey → persona display name for bot members. */
5556
personaLookup?: Map<string, string>;
@@ -148,6 +149,7 @@ const MessageTimelineBase = React.forwardRef<
148149
hasComposerOverlay = true,
149150
hasOlderMessages = true,
150151
isFetchingOlder = false,
152+
layoutShiftKey = null,
151153
followThreadById,
152154
isFollowingThreadById,
153155
isMessageUnreadById,
@@ -242,6 +244,7 @@ const MessageTimelineBase = React.forwardRef<
242244
hasOlderMessages,
243245
isFetchingOlder,
244246
isLoading: showTimelineSkeleton,
247+
layoutShiftKey,
245248
messages: deferredMessages,
246249
onTargetReached,
247250
scrollContainerRef,

‎desktop/src/features/messages/ui/useAnchoredScroll.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type UseAnchoredScrollOptions = {
3838
* restoration re-run trigger so the anchor reasserts itself around the
3939
* prepend on the fetch-state toggle, not only on the `messages` change. */
4040
isFetchingOlder?: boolean;
41+
/** Re-runs restoration when surrounding chrome changes size without changing messages. */
42+
layoutShiftKey?: string | number | null;
4143
/** When set, scroll to and highlight this message on mount and on change. */
4244
targetMessageId?: string | null;
4345
onTargetReached?: (messageId: string) => void;
@@ -212,6 +214,7 @@ export function useAnchoredScroll({
212214
fetchOlder,
213215
hasOlderMessages = false,
214216
isFetchingOlder = false,
217+
layoutShiftKey = null,
215218
targetMessageId = null,
216219
onTargetReached,
217220
}: UseAnchoredScrollOptions): UseAnchoredScrollResult {
@@ -363,7 +366,7 @@ export function useAnchoredScroll({
363366
// before the render. This is the single mechanism for keeping scroll
364367
// stable across prepends, appends, image loads, embed expansions, etc.
365368
// ---------------------------------------------------------------------------
366-
// biome-ignore lint/correctness/useExhaustiveDependencies: `isFetchingOlder` is an intentional re-run trigger, not a read. It re-runs restoration on fetch-state toggles so the anchor reasserts itself around the prepend; the correction is a no-op when nothing above the anchor moved.
369+
// biome-ignore lint/correctness/useExhaustiveDependencies: `isFetchingOlder` and `layoutShiftKey` are intentional re-run triggers, not reads. They re-run restoration when fetch state or surrounding layout changes so the anchor reasserts itself; the correction is a no-op when nothing above the anchor moved.
367370
React.useLayoutEffect(() => {
368371
const container = scrollContainerRef.current;
369372
if (!container) return;
@@ -456,6 +459,7 @@ export function useAnchoredScroll({
456459
}, [
457460
isFetchingOlder,
458461
isLoading,
462+
layoutShiftKey,
459463
messages,
460464
onTargetReached,
461465
scrollContainerRef,

0 commit comments

Comments
 (0)