Skip to content

Conversation

@tiensi
Copy link
Contributor

@tiensi tiensi commented Aug 26, 2025

Summary
Added scroll state memory when navigating back from session view. This works for filtered search results as well.

Changes

  • Added showSessionHistory to SessionsView to replace reliance on selectedSession being null
  • Passed selectedSession as a new prop to SessionListView so that it can scroll to a selected session
  • Added useEffect with MutationObserver to detect and scroll to selected session when loaded.

Request
#3664

After Changes

Screen.Recording.2025-08-26.at.2.03.27.PM.mov

NOTE
Previous PR was closed out due to staleness. Comments were addressed in this pr

@tiensi tiensi changed the title Added auto-scroll to most recently selected chat history feat: Added scroll state support for chat-session-list navigation Aug 26, 2025
@tiensi tiensi force-pushed the tiensi/retain-chat-session-position branch from 0e9c9bc to 19216df Compare August 26, 2025 21:09
@tiensi tiensi marked this pull request as ready for review August 26, 2025 21:11
Copy link
Collaborator

@zanesq zanesq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! Couple of notes:

  1. It doesn't seem to respect the scroll after searching, it just goes back to the top when I hit back (see below). I don't think this is a blocker since the general back scroll position without search is a valuable feature but if that was the intent just wanted to point it out.
Kapture.2025-08-27.at.08.54.53.mp4
  1. Using mutation observer is not ideal, we'd rather stick with react way of doing things. MutationObserver is typically a workaround for situations where you don’t have direct control over the DOM updates (such as with third-party libraries or dynamic content outside React’s control).

Can you change it to use refs instead something like

import React, { useEffect, useRef } from "react";

function SessionListView({ sessions, selectedSessionId, ...props }) {
  const sessionRefs = useRef({});

  useEffect(() => {
    if (selectedSessionId && sessionRefs.current[selectedSessionId]) {
      sessionRefs.current[selectedSessionId].scrollIntoView({
        block: "center",
        behavior: "smooth",
      });
    }
  }, [selectedSessionId, sessions]); // or filteredSessions if applicable

  return (
    <div>
      {sessions.map(session => (
        <Card
          key={session.id}
          ref={el => {
            // Store ref for each session card
            sessionRefs.current[session.id] = el;
          }}
          // ...other props
        >
          {/* ... */}
        </Card>
      ))}
    </div>
  );
}

@tiensi
Copy link
Contributor Author

tiensi commented Aug 27, 2025

Thank you for the review! I'll go ahead and make your suggested changes.

It doesn't seem to respect the scroll after searching

I actually wanted to have a separate follow up to preserve the search-filter on back which would make it easier to reuse this scroller.

Using mutation observer is not ideal

Got it! I'm still getting a handle on react so I appreciate the heads up.

@tiensi
Copy link
Contributor Author

tiensi commented Aug 27, 2025

I went ahead and pushed up the suggested changes:

  • Replaced MutationObserver with useRef<Record<string, HTMLElement>>({});
  • Kept scrollIntoView({block: "center"}) (there was a separate suggestion that smooth scroll experience is poor if a user scrolls all the way to the bottom and toggles back and forth)
  • Updated useEffect to listen to [selectedSessionId, sessions] which should operate better with element ref.

@tiensi tiensi requested a review from zanesq August 27, 2025 17:47
@tiensi tiensi force-pushed the tiensi/retain-chat-session-position branch from c331f3d to c1eeb6c Compare August 27, 2025 17:49
@zanesq zanesq merged commit 6610496 into block:main Aug 28, 2025
10 checks passed
michaelneale added a commit that referenced this pull request Aug 28, 2025
* main: (38 commits)
  feat: linux computer control for android (termux) (#3890)
  feat: Added scroll state support for chat-session-list navigation (#4360)
  docs: typo fix (#4376)
  blog: goose janitor (#4131)
  Fix eleven labs audio transcription and added more logging (#4358)
  feat: re-introduce session sharing (#4370)
  remove duplicate blog post (#4369)
  fix focus ring under form submits (#4332)
  Trigger docs deployment
  update tetrate blog date to today (#4368)
  tetrate signup: blog/launch post (#4313)
  Implement graceful recipe error handling with filename display (#4363)
  docs: airgapped operation by bypassing hermit for desktop app (#4063)
  remove Ollama card from welcome screen (#4348)
  feat: initial implementation of extension malware check (#4272)
  Add Tetrate Agent Router Service to Provider Registry (#4354)
  Goose Simple Compact UX (#4202)
  Refactor Extensions Install Modal (#4328)
  fix: url path trailing slash for custom-providers (#4345)
  docs: update available and onboarding providers list (#4356)
  ...
lifeizhou-ap added a commit that referenced this pull request Aug 29, 2025
* main: (40 commits)
  new recipe to lint-check my code (#4416)
  removing a leftover syntax error (#4415)
  Iand/updating recipe validation workflow (#4413)
  Iand/updating recipe validation workflow (#4410)
  Fix (Ollama provider): Unsupported operation: streaming not implemented (#4303)
  change databricks default to claude sonnet 4 (#4405)
  Iand/updating recipe validation workflow (#4406)
  Add metrics for recipe metadata in scheduler, UI, and CLI (#4399)
  Iand/updating recipe validation workflow (#4403)
  making small updates to recipe validation workflow (#4401)
  Automate OpenRouter API Key Distribution for External Recipe Contributors (#3198)
  Enhance `convert_path_with_tilde_expansion` to handle Windows (#4390)
  make sure all cookbook recipes have a title and version, but no id (#4395)
  Nest TODO State in session data (#4361)
  Fast model falls back to regular (#4375)
  Update windows instructions (#4333)
  feat: linux computer control for android (termux) (#3890)
  feat: Added scroll state support for chat-session-list navigation (#4360)
  docs: typo fix (#4376)
  blog: goose janitor (#4131)
  ...
dorien-koelemeijer pushed a commit to dorien-koelemeijer/goose that referenced this pull request Sep 2, 2025
…ock#4360)

Signed-off-by: Dorien Koelemeijer <dkoelemeijer@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants