Skip to content

useScrollEdge observes firstElementChild, which is usually a detached loading skeleton #41

Open

Description

@anildukkipatty

Problem

ui/app/lib/use-scroll-edge.ts:33 observes firstElementChild of the scroller.

On a cold load the first child is the {loading && ...} skeleton. Once loading flips, that node is unmounted — so the ResizeObserver is left watching a detached node, not merely the wrong one. It never recovers for the rest of the session.

Separately, the first-child idiom is the wrong shape for this container generally: .chat-body is a flex column whose newest content is its last child, and whose child set turns over on every commit.

Impact

Low, and the hook degrades rather than breaks. The scroller itself is still observed for viewport resizes, and onScroll supplies the direction delta the fade actually keys off. The only lost signal is "content grew while nobody scrolled" — i.e. the edge fades can go stale during streaming without a scroll event to correct them.

Why it wasn't fixed inline

Raised during the chat scroll work (4ec1b4f → d5bb93f) and deliberately deferred — it fails "trivial and low-risk":

  • The honest fix is a MutationObserver inside the hook, not a one-liner.
  • Eight call sites ride on this hook: app-shell.tsx (×2), marketplace, marketplace-bot-details, and share-modals (×4).
  • None of them are test-covered, and all are browser-only to verify.

Widening the cosmetic fade fix to touch all eight was judged worse than leaving the weakness documented.

Suggested approach

  • MutationObserver on the scroller to re-target (or drop child observation entirely if the scroller + onScroll signals turn out to be sufficient — worth measuring first).
  • Audit all eight call sites for whether they actually need a content signal, or only the scroller's own geometry.
  • Needs browser verification: there is no jsdom or Playwright in this repo.

Related

Fixed next door in the same area: the stale-key bug that stopped the edge listeners binding at all on a cold load (d5bb93f), and the stick-to-bottom rework in 0a83797, 621c9d8, cb686b1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions